I've been attempting to utilize the .map method in order to create a new array named workspaces
, containing only the ids from the existing array. However, despite the console.log() displaying the ids as expected, the return
statement does not populate the workspaces array with these ids.
const workspaces = this.networkTree.map( (group) => {
group.units.map( (unit) => {
console.log(unit.id); // The id is correctly displayed in the console e.g '12345'
return unit.id;
});
});
console.log(workspaces); // Each sub-array within workspaces appears empty (referenced image below)