I have an array of objects, I'm trying to loop through them via map function and create an output as follows:
Desired output
dataSet = [
[John, Doe, Sales],
[Jane, Doe, HR],
[Jack, Doe, Manager]
]
My array of objects:
[[object],[object],[object]]
Here is what I have tried so far:
users.map((item) => {
dataSet.push(item.profile.firstName, item.profile.role)
})
However my output:
["John","Jane","Jack"]
How can I push each loop into new array?
Thanks
.map()then you're using.map()incorrectly and should be using.forEach()instead.[[{...}],[{...}]], or an array of objects[{...},{...}]