Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
How to change value of object which is inside an array

I have an array that contains a set of objects And in these objects I want to change the value of a property :

var array=[{a:1, b:false}, {a:2, b:true}, {a:3, b:false}]

I want the propriety b to be true everywhere

var array=[{a:1, b:true}, {a:2, b:true}, {a:3, b:true}]

How do I do this?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Just use a loop with map:

const newArr = array.map((item) => ({ ...item, b: true }));
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can use two possible approaches:

  1. you can use forEach as follow:
yourArray.forEach(item=>item.b = true);
  1. or if you want to build new array use map as follow:
const updatedArray = temp.map(item=>{...item, b:true});
about 4 years ago · Juan Pablo Isaza Denunciar

0

There are 2 ways you can achieve the result:

  1. Using forEach:

var array=[{a:1, b:false}, {a:2, b:true}, {a:3, b:false}]
array.forEach((obj) => {
   return obj.b = true
})

console.log(array)

  1. Using map:

var array=[{a:1, b:false}, {a:2, b:true}, {a:3, b:false}];

const result = array.map((item) => ({ ...item, b: true }));

console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda