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

240
Views
How can I get key values and correspond it to each other in js?

I have an array of objects as follow:

[
    {
        "card_key": "Edition",
        "card_value": "Elite Fight Night"
    },
    {
        "card_key": "Card ID",
        "card_value": "15824885587"
    }
]

and I want the output as follow:

{
  "Edition":"Elite Fight Night",
  "Card ID":"15824885587"
}

How can I do this in javaScript? I m beginner of js. Not know how can I do this

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

0

Just iterate through the array and save the value of card_key as key and card_value as the value for your new object.

Something as shown below

    
obj_array = [
    
    {
        "card_key": "Edition",
        "card_value": "Elite Fight Night"
    },
    {
        "card_key": "Card ID",
        "card_value": "15824885587"
    }
    ]

objs1 = {}

for (const x of obj_array)

    objs1[x["card_key"]] = x["card_value"]

console.log(objs1)
    

about 4 years ago · Juan Pablo Isaza Report

0

You can use map and Object.fromEntries

const data = [
    {
        "card_key": "Edition",
        "card_value": "Elite Fight Night"
    },
    {
        "card_key": "Card ID",
        "card_value": "15824885587"
    }
]

const result = Object.fromEntries(data.map(d => [d.card_key, d.card_value]))

console.log(result)

about 4 years ago · Juan Pablo Isaza Report

0

let arr = [
{
    "card_key": "Edition",
    "card_value": "Elite Fight Night"
},
{
    "card_key": "Card ID",
    "card_value": "15824885587"
}
];
let finalObj = {};
for(let i = 0; i < arr.length; i++) {
    let obj = arr[i];
    finalObj[obj['card_key']] = obj['card_value'];
}
console.log(finalObj);

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!