I have a input object of two array
payload
columns:["col1" , "col2","col3"],
data: ["col1value1","col2value1" , "col1value3"] ,
["col1value2","col2value2" , "col1value2"]
Now I want to convert this two array of objects like below output = [];
[
{ col1: 'col1value1', col2: 'col2value1', col3: col1value3},
{ col1: 'col1value2', col2: 'col2value2', col3: col1value2}
]
trying to use reduce or other methods -- but not getting it - have to hard code index of column in data array . is there any better and fast way? in which it will done without hard coding the column names.
currently doing like
const indexofCol1= this.payload.columns.indexOf["col1"]
then using that index to map in data array to get all the values -- which is not a good way .