I hope the title and this description aren't too confusing.
WHAT I HAVE: An object containing two parent-objects (firstGroup and secondGroup). Each contains the children-objects.
const dataObject = {
firstGroup: {
0: {
title: '0-firstGroup',
description: '0th item in firstGroup!',
added: 2018,
},
1: {
title: '1-firstGroup',
description: '1st item in firstGroup!',
added: 2019,
},
2: {
title: '2-firstGroup',
description: '2nd item in firstGroup!',
added: 2020,
},
},
secondGrounp: {
0: {
title: '0-secondGroup',
description: '0th item in secondGroup!',
delicate: true,
timestamp: '10:30:25',
},
1: {
title: '1-secondGroup',
description: '1st item in secondGroup!',
delicate: true,
timestamp: '14:03:11',
},
},
};
DESIRED RESULTS: I'd like the returned object's properties to be parent-arrays, containing the respective children-objects as elements.
resultsDesired: {
firstGroup: [
{
title: '0-firstGroup',
description: '0th item in firstGroup!',
added: 2018,
},{
title: '1-firstGroup',
description: '1st item in firstGroup!',
added: 2019,
},{
title: '2-firstGroup',
description: '2nd item in firstGroup!',
added: 2020,
},
],
secondGrounp: [
{
title: '0-secondGroup',
description: '0th item in secondGroup!',
delicate: true,
timestamp: '10:30:25',
}, {
title: '1-secondGroup',
description: '1st item in secondGroup!',
delicate: true,
timestamp: '14:03:11',
},
],
};
BONUS RESULTS: If you'd be willing to try this out as well, I'd also be interested in the returned object's properties to be parent-objects, containing label's of the parent identifiers and group-arrays with the children-objects as elements.
resultsBonus: {
firstGroup: {
label: 'firstGroup',
group: [
{
title: '0-firstGroup',
description: '0th item in firstGroup!',
added: 2018,
}, {
title: '1-firstGroup',
description: '1st item in firstGroup!',
added: 2019,
}, {
title: '2-firstGroup',
description: '2nd item in firstGroup!',
added: 2020,
},
],
},
secondGrounp: {
label: 'secondGroup',
group: [
{
title: '0-secondGroup',
description: '0th item in secondGroup!',
delicate: true,
timestamp: '10:30:25',
}, {
title: '1-secondGroup',
description: '1st item in secondGroup!',
delicate: true,
timestamp: '14:03:11',
},
],
},
};
EDIT - MY PREVIOUS ATTEMPT: @RyanWilson made a good point, I should have shown that I actually attempted this. Made lots of attempts, all of which were terrible. Below is the last one before asking...
const arr = [];
Object.keys(dataObject).forEach((key) => {
arr.push(dataObject[key]);
});
console.log('arr ', arr);
/* LOG
[
0: {
0: {
title: "0-firstGroup"
description: "0th item in firstGroup!"
added: 2018
},
1: {
title: "1-firstGroup"
description: "1st item in firstGroup!"
added: 2019
},
2: {
title: "2-firstGroup"
description: "2nd item in firstGroup!"
added: 2020
},
},
1: {
0: {
title: "0-secondGroup",
description: "0th item in secondGroup!",
delicate: true,
timestamp: "10:30:25",
},
1: {
title: "1-secondGroup",
description: "1st item in secondGroup!",
delicate: true,
timestamp: "14:03:11",
},
},
]
*/