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

202
Views
Cómo fusionar un número desconocido de objetos en uno usando lodash

Estoy trabajando en un proyecto nativo de reacción y recibo datos de API simplemente así

 [ { "value":[1,2,3.....1250] //each have max 1250 item, can be have multi of them }, { "value":[1,2,3.....1230] } ]

El problema es que no sé cuántos elementos como este, tal vez 3,4 objetos tienen 1250 elementos, no lo sé, así que mi pregunta es cómo fusionar 2, o cualquier objeto más grande que un solo objeto, el valor del objeto se verá así si solo tenemos 2 objetos:

 [ { "value":[1,2,3...1250,1,2,3..1230]. //will have every value of two object } ]

¿Cómo puedo hacer esto en lodash?

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

0

No necesitas lodash. Puede hacer esto simplemente con el método JS Reduce.

Si realmente quieres usar lodash, entonces

_ is importing lodash as _

 _.reduce(arr, (currentArray, currentValueObject) => ([{ value: [...currentArray[0].value, ...currentValueObject.value] //concatenate current object value to the object valules till now }]), [{ value: [] //the final value array inside object }]) 

 var arr = [{ "value": [1, 2, 3, 1250] //each have max 1250 item, can be have multi of them }, { "value": [1, 2, 3, 1230] } ] var result = arr.reduce((currentArray, currentValueObject) => ([{ value: [...currentArray[0].value, ...currentValueObject.value] //concatenate current object value to the object valules till now }]), [{ value: [] //the final value array inside object }]) console.log(result);

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!