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

107
Views
Modified array of object with value from a given object TS/JS

Guys what is the best approach to modified array of object with value from object. E.g: lets say that we have array and object like this:

let arr = [
{
        parameter: 'aaa', 
        isSomething: false
},
{
        parameter: 'bbb', 
        isSomething: false
}, 
{
        parameter: 'ccc', 
        isSomething: false
}
];

let obj = {aaa: false, bbb: true, ccc: true}

and output that I want to achieve is:

let arr = [
{
        parameter: 'aaa', 
        isSomething: false
},
{
        parameter: 'bbb', 
        isSomething: true
}, 
{
        parameter: 'ccc', 
        isSomething: true
}
];

Could you help me with this one? I would be grateful. Thanks

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

0

You can use Arra#map() combined with Destructuring assignment

Code:

const arr = [{parameter: 'aaa',isSomething: false},{parameter: 'bbb',isSomething: false},{parameter: 'ccc',isSomething: false}]

const obj = {
  aaa: false,
  bbb: true,
  ccc: true
}

const result = arr.map(({ parameter, isSomething }) => ({ 
  parameter, 
  isSomething: obj[parameter]
}))

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!