2
I need to multiply each user’s age by 2 and change it in each object. How do I change the value?
const usuarios = [
{ nome: 'Diego', idade: 23, empresa: 'Rocketseat' },
{ nome: 'Gabriel', idade: 15, empresa: 'Rocketseat' },
{ nome: 'Lucas', idade: 30, empresa: 'Facebook' },
];
for (let usuario of usuarios) {
const multiplicarIdade = usuario.idade * 2
}
console.log(usuarios)
Expected result:
// Resultado:
[
{ nome: 'Diego', idade: 46, empresa: 'Rocketseat' },
{ nome: 'Gabriel', idade: 30, empresa: 'Rocketseat' },
]
So, the original proposal was to multiply the age of each user by 2 and finally return the age of users under 50. I used everyone’s tip, but like
ḿap
creates the copy of the original, but with new values, within this scenario it became more interesting to use it.– andrebonfim