-2
I have an array of objects and need to create a function that takes this array and returns a new array with new modified objects. See the example below:
function increase_age(users) {
for (user of users) {
user.age ++;
}
return users;
}
const users = [{name: "Lucas", age: 21}, {name: "Maria", age: 23}];
const new_array = increase_age(users);
In the example above, the objects of users
are also changed after function call.
What I want is to make a copy of these objects so that they are changed without affecting the original objects. How can I do this in pure Javascript?
Dear Jean copy as the suggestions Inkei and change later what you have to change.
– Guilherme Nascimento
Thank you William, I had not found this issue on the site.
– JeanExtreme002