I called API Called and fetch the array like this.
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: {…}}
I want convert above object array to the object. Like below..
"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"}
I tried but I can not convert like this. Please anyone know how to convert this help me. Thank you
I called API Called and fetch the array like this.
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: {…}}
I want convert above object array to the object. Like below..
"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"}
I tried but I can not convert like this. Please anyone know how to convert this help me. Thank you
Share Improve this question edited Jul 13, 2019 at 5:56 Chanaka asked Jul 13, 2019 at 5:48 ChanakaChanaka 7781 gold badge11 silver badges22 bronze badges 2- 2 please post the code also you have tried so far – Code Maniac Commented Jul 13, 2019 at 5:58
- 1 that's a javascript issue – Rodrigo Commented Jul 13, 2019 at 6:32
2 Answers
Reset to default 5You can use Object.assign()
and spread syntax like this:
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)
You can use reduce
to achieve this
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)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745220217a4617214.html
评论列表(0条)