Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda