[英]how to convert Nested Object to an Nested array for react native tablee
[英]How to convert Array Object to Object in React native
我调用 API Called 并像这样获取数组。
0:
2019-07-25: {title: "Sub task for 11"}
__proto__: Object
1: {2019-07-19: {…}}
2: {2019-07-24: {…}}
3: {2019-07-26: {…}}
4: {2019-07-25: {…}}
5: {2019-07-24: {…}}
6: {2019-07-25: {…}}
7: {2019-07-25: {…}}
我想将上面的对象数组转换为对象。 像下面..
"2019-07-25": {title: "Sub task for 11"},
"2019-07-19": {title: "Sub task for 12"},
"2019-07-24": {title: "Sub task for 13"},
"2019-07-26": {title: "Sub task for 14"}
我试过了,但我不能像这样转换。 请任何人知道如何转换这个帮助我。 谢谢
您可以像这样使用Object.assign()
和传播语法:
const input = [ { "2019-07-25": { title: "Sub task for 11" } }, { "2019-07-19": { title: "Sub task for 12" } }, { "2019-07-24": { title: "Sub task for 13" } } ]; const output = Object.assign({}, ...input) console.log(output)
您可以使用reduce
来实现此目的
var res = [ { "2019-07-25": { title: "Sub task for 11" } }, { "2019-07-19": { title: "Sub task for 12" } }, { "2019-07-24": { title: "Sub task for 13" } } ].reduce((a, b) => ({ ...a, ...b })) console.log(res)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.