I have an array of objects which is coming from server response.
Array structure:
[
{
col1: ["a", "b"],
col2: ["c", "d"]
},
{
col1: ["e", "f"],
col2: ["g", "h"]
}
]
I want the desired output array to be in this form:
[
{
col1: "b",
col2: "d"
},
{
col1: "f",
col2: "h"
}
]
Basically I want to convert the Object keys Value which is an array initially to a single value and that value will be second element of the Object keys array.
I am able to do the conversion by converting Object Keys array to comma seperated string using toString()
, then do string.split(",")[1]
but I am not able to iterate through the Object keys.
Would prefer the inputs in ES6 using map for iteration