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

142
Vistas
Replace nested array for new array

I have an array inside another array:

Structure:

First Array
[
{
Second Array
   [
     {
     }
   ]
}
]

So I want to replace all Second Array for new array that I have so I try this:

this.FirstArray.map(
          (myArray) =>
            myArray.SecondArray === this.MyNewArray
        )

But this is not replacing for my new array it still having old values. What am I doing wrong?

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

0

Normally, the map() method will return a new array.

// Assume that your nested array looks like so:
let nestedArray = [
    ["A", "B", "C"],
    ["E", "F", "G"]
]

// Assume that this is the new array
const newArray = [1, 2, 3]

nestedArray = nestedArray.map(el => newArray);

// expected output: nestedArray [[1, 2, 3], [1, 2, 3]]
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can achieve that by using spread operator and without any loop as you want to replace second array with the new array.

Input array :

First Array
[{
  Second Array
   [{}]
}]

Logic to replace newArray with secondArray :

FirstArray[0].secondArray = [ ...newArray ]

Demo :

const firstArray = [{
    secondArray: ['alpha', 'beta', 'gamma']
}];

const newArray = ['A', 'B'];

firstArray[0].secondArray = [ ...newArray ];

console.log(firstArray);

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