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

104
Views
Combinar dos matrices de objetos con las mismas claves en JavaScript

Me gustaría fusionar estas dos matrices

 const arr1 = [{ label: 'one', value: 'one', type: 'arr1'}]; const arr2 = [{ label: 'two', value: 'two', type: 'arr1'}];

para obtener el siguiente resultado

 const arr3 = [{ label: 'one', value: 'one' type: 'arr1'}, { label: 'two', value: 'two' type: 'arr1'}];

arr1.concat(arr2) y _.merge(arr1, arr2) y [arr1, arr2] y obtuve el siguiente error

 TypeError: Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Su tercer intento [arr1, arr2] estuvo muy cerca de una respuesta correcta, puede usar la nueva sintaxis extendida (...) para concatenar las matrices haciendo lo siguiente:

 const arr1 = [{ label: "one", value: "one", type: "arr1" }]; const arr2 = [{ label: "two", value: "two", type: "arr1" }]; console.log([...arr1, ...arr2]);

about 4 years ago · Juan Pablo Isaza Report

0

Puedes probar este código, funciona bien:

 const arr1 = [{ label: 'one', value: 'one', type: 'arr1'}]; const arr2 = [{ label: 'two', value: 'two', type: 'arr1'}]; const arr3 = arr1.concat(arr2); console.log(arr3);

about 4 years ago · Juan Pablo Isaza Report

0

Te perdiste la coma antes de type

Pero puedes resolverlo de esa manera.

 const arr1 = [{ label: 'one', value: 'one', type: 'arr1'}]; const arr2 = [{ label: 'two', value: 'two', type: 'arr1'}]; const arr3 = arr1.concat(arr2); console.log(arr3);

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!