I have a multidimensional javascript array of objects that I am trying to use to simply collate both the id and its key within the unit array to a brand new array
What is the best solution for returning the id with the key within its units array but reversed so the key of the new array is the unit id
[
{
units: [
{
id: 10000282,
name: "Group 1",
},
{
id: 10000340,
name: "Group 2",
},
{
id: 10000341,
name: "Group 3",
},
],
},
{
units: [
{
id: 10000334,
name: "Group 4",
},
],
},
]
Expected output - just return an array in the following format e.g
ids = [ 10000282 => 0, 10000340 => 1, 10000341 => 2, 10000334 => 0 ]
so 10000282 would be the key, and 0 would be the value for the first iteration of the array
-- update --
I probably didn't explain the output so well the output should be as follows but in an array format.
ids[10000282] = 0
ids[10000340] = 1
ids[10000341] = 2
ids[10000334] = 0
ids[10000341]in the console and it would return the value 2