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

128
Views
How to set object value as key to other value of object

current data

[ 
  {
    "id": 0,
    "name": "Active",
    "value": "Y",
    z"
  },
  {
    "id": 1,
    "name": "controls",
    "value": "N",  
  }
]

result data


  {"Active":"Y",
  "controls":"N"}

how to map value of one item in object as another item key ( as one object)

about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

x = [{
    "id": 0,
    "name": "Active",
    "value": "Y",
  },
  {
    "id": 1,
    "name": "controls",
    "value": "N",
  }
]

a = x.reduce((a, b) => ({...a,  [b.name]: b.value }), {})

console.log(a)

s = x.map(item => ({ [item.name]: item.value }))

console.log(s)

about 4 years ago · Santiago Gelvez Report

0

const data = [ 
{ "id": 0, "name": "Active", "value": "Y" }, 
{ "id": 1, "name": "controls", "value": "N" },
]


const result = data.map(item => {
  return {
    [item.name]: item.value
  }
})

console.log(result)

about 4 years ago · Santiago Gelvez Report

0

I think you want this:

let elements = [ { "id": 0, "name": "Active", "value": "Y"}, 
    { "id": 1, "name": "controls", "value": "N"},
] 


let new_element = Object()

elements.forEach(element=>{     
    new_element[element.name] = element.value
})
console.log(new_element)
about 4 years ago · Santiago Gelvez 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!