My array structure is quite complex with multiple objects containing different properties.
let arr = [
{ id: 1, name: "tony", hatColor: "blue" },
{ id: 2, name: "larry", hatColor: "red" },
{ id: 3, name: "stuart", hatColor: "green" },
];
I am looking to extract specific arrays for each key in the main array - one for ids, one for names, and one for hat colors.
idArr = [1, 2, 3];
nameArr = [tony, larry, stuart];
hatColorArr = [blue, red, green];
However, the exact structure of the array of objects may vary as it is generated dynamically.
My attempt to achieve this using nested loops and mapping has resulted in an array of undefined values. I am hoping for a more efficient way to accomplish this without hardcoding numerous if statements.
Any help or suggestions would be greatly appreciated. Thank you.