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

79
Vistas
Replace element from first array by another element of second array

I am having this issue replacing element from first array by another element of second array.

For exapmle if I have one array haiving some empty values and string like this:

let array_1 = [empty, 'Connected', empty, 'Connected', 'Connected'];

And another new array will be like this:

let array_2 = [empty, 'Updated'];

So, New updated array with replaced element will look like this:

newArray = [empty, 'Updated', empty, 'Connected', 'Connected'];

I tried with for loop and by using findIndexof, but could not replace the element with exact index address.

One of them which worked for me partially is:

console.log(Object.values(...array_1, ...array_2));

Out of above line is just one array with one element, not reast of element from array_1:

['Updated']

But it seems like Obejct.values() does not work with element generated as a empty.

Any possible solution on this would be great!

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

0

If I understood it properly you can solve it by using map function like this:

let array_1 = [undefined, "Connected", undefined, "Connected", "Connected"];
let array_2 = [undefined, "Updated"];

const res = array_1.map((val, idx) => {
  return array_2[idx] || val;
});
console.log(res);

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