I'm dealing with an immutable map and iterating through an array to create objects that I want to place inside the map. What would be the correct approach to achieve this? Below is my current code snippet:
let arrayOfNames = ['John', 'Lisa'];
arrayOfNames.forEach(function(name) {
let id = generateId();
let newPerson = {
id: id,
name: name,
};
// people represents the immutable map
people.set(id, newPerson);
});
The issue is that when I try to console.log(people), John and Lisa are not included in the output because people is immutable.
I have a solution for inserting one element into the map and assigning it to a new variable:
let newPeople = people.set('3', {id: 3, name: 'John'});
But how can I handle this when I need to iterate through multiple elements?