Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
Reemplazar matriz anidada por nueva matriz

Tengo una matriz dentro de otra matriz:

Estructura:

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

Así que quiero reemplazar toda la segunda matriz por una nueva matriz que tengo, así que intento esto:

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

Pero esto no está reemplazando a mi nueva matriz, todavía tiene valores antiguos. ¿Qué estoy haciendo mal?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Normalmente, el método map() devolverá una nueva matriz.

 // 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 Report

0

Puede lograrlo utilizando el operador de propagación y sin ningún bucle, ya que desea reemplazar la segunda matriz con la nueva matriz.

Matriz de entrada :

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

Lógica para reemplazar newArray con secondArray :

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

demostración :

 const firstArray = [{ secondArray: ['alpha', 'beta', 'gamma'] }]; const newArray = ['A', 'B']; firstArray[0].secondArray = [ ...newArray ]; console.log(firstArray);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!