So i have this format of data, i’m trying to make the sub value of JSON as a key,
I don’t have any idea how to approach, Need help
var what_i_have = [
{
"one":"1",
"test":[
"two",
"2"
]
}
]
var what_i_need = [
{
"one":"1",
"two":"2"
}
]
2
Answers
You can
map()
over the array and create new object were you keepone
, and add a key fromtest[0]
with valuetest[1]
.You could check for the nested array and take the entries or the entries from the outer properties.