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

141
Views
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
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!