Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
How to merge unknown number of object into one using lodash

I'm working on a react-native project, and receive data from api just simple like this

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

Problem is, i don't know how many item like this, maybe 3,4 object have 1250 item, i don't know, so my question is,how to merge 2, or any bigger than single object, object value will look like this if we only have 2 object:

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

How can i do this in lodash??

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You don't need lodash . You can do this simply with JS Reduce method.

If u really want use lodash, then

_ 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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda