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

105
Vistas
How can I assign array values into object keys for other object?

So I have an array of objects [{}, {}, {}] and simple array [true, false, true]

Is there any way to make first array [{value: true}, {value: false}, {value: true}]?

I mapped over the object array

const a = [{a: 1}, {a: 2}, {a: 3}] const b = [true, false, true]  const c = a.map((item) => {...item, value: }) 

I don't understand how to assign the value from the second array.

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

0

Assuming your array of objects is called objects and your simple array is called array, then you can execute:

objects.forEach((o, i) => o['value'] = array[i])
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can map each element of the array to the object:

console.log([true, false, true].map(el => ({ value: el })));

or if you want to overwrite the elements in the first array

const arr = [{}, {}, {}];
const arr2 = [true, false, true];
arr.forEach((el, idx) => el.value = arr2[idx]);

console.log(arr);

about 4 years ago · Juan Pablo Isaza Denunciar

0

An alternative way of accomplishing this is by using the unshift() method which will add the new elements to the beggining of the array.

var arr1 = [true, false, true], arr2 = [{}, {}, {}];
for(el of arr1){ arr2.unshift({'value': el}) }
console.log(arr2);

If you want to loose the last three empty objects in the array, slice them like so: arr2.slice(0,3)

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