If you want a quick solution for an unmutable version of .map
over an array of objects you can use the spread operator:
myArrayOfObjects.map(({...obj}) => { });
Example:
const foo = [];
for(let i = 0; i < 5; i++) {
foo.push({label: "foo"});
}
const bar = foo.map(({...val}) => {
val.id = Math.random();
return val;
});
console.log(foo);
console.log(bar);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…