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
>Solution :
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)