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

142
Visualizações
How to deal with this data structure in javascript

I'm stuck on a problem and I've no idea in which direction should I go. There is a array of objects and I want to check if there was previously exact type, if so then copy the properites and add new one without a type property, if not push the object to the array.

Example 1:

Expected input:

const arr = [
    {type: 1, amount: 100},
    {type: 2, amount: 200},
    {type: 3, amount: 300},
]

const obj = {type: 1, name: 'PLN'}

Expected output:

arr = [
    {type: 1, amount: 100, name: 'PLN'},
    {type: 2, amount: 200},
    {type: 3, amount: 300},
]

Example 2:

Expected input:

const arr = [
    {type: 1, amount: 100},
    {type: 2, amount: 200},
    {type: 3, amount: 300},
]

const obj = {type: 4, amount: 400}

Expected output:

arr = [
    {type: 1, amount: 100},
    {type: 2, amount: 200},
    {type: 3, amount: 300},
    {type: 4, amount: 400},
]

If something is unclear please let me know :)

about 4 years ago · Juan Pablo Isaza
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