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

125
Views
merge Object and array mapping object key

Merge one object into array object basis on object key and array object key mapped

{
'id':49,
'city':'bangalore',
'country':'India'
}
arr=[{
{title: 'Location ID', field: 'id', width: 200, _width: 200, filter: 'text'},
{title: 'City', field: 'city', width: 200, _width: 200, filter: 'dropdown'},
{title: 'Country', field: 'country', width: 200, _width: 200, filter: 'dropdown'}
}]

expected results:
[{
{'id':49,title: 'Location ID', field: 'id', width: 200, _width: 200, filter: 'text'},
{'city':'bangalore',title: 'City', field: 'city', width: 200, _width: 200, filter: 'dropdown'},
{'country':'India',title: 'Country', field: 'country', width: 200, _width: 200, filter: 'dropdown'}
}]```

I tried below code
console.log([...Obj,...arr])
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use Array.prototype.map() combined with Destructuring assignment

Code:

const obj = { id: 49, city: 'bangalore', country: 'India' }
const arr = [{title: 'Location ID',field: 'id',width: 200,_width: 200,filter: 'text',},{ title: 'City', field: 'city', width: 200, _width: 200, filter: 'dropdown' },{title: 'Country',field: 'country',width: 200,_width: 200,filter: 'dropdown',},]

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

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!