I tried to loop array element into the object. I tried the given method but i got some errors in it. Loop object keys and their values based on the array.
let headings = ['sam', 'ram', 'ham'.....];
let dataHeading = ['headingOne', 'headingTwo', 'headingThree'....];
let data = ['one', 'two', 'three'.....];
let finaldata;
for(let i=0; i<headings.length; i++){
finaldata = {
heading[i]: {
dataHeading[i] : data[i]
}
}
}
console.log(finaldata);
//what i want as a output is
{
sam: {
headingOne: one
},
ram: {
headingTwo: two
},
ham: {
headingThree : three
}
}