let header = [];
for (let index = 0; index < 4; index++) {
header.push(`header${index}`);
}
let datacell = [];
for (let index = 0; index < 64; index++) {
datacell.push(`datacell${index}`);
}
let Data = [];
let tempObj = {};
for (let j = 0; j < datacell.length; j++) {
for (let k = 0; k < header.length; k++) {
if (j % header.length === k) {
tempObj[header[k]] = datacell[j];
if (k === header.length - 1) {
Data.push(tempObj);
console.log(tempObj);
}
}
}
}
console.log(Data);
Whille consoling tempObjs output are as expecting, but when tempObj is pushed to the array the previous elements are overriding by new element.
I was expecting output like
[
{
header0: datacel0,
header1: datacel1,
header2: datacel2,
header3: datacel3,
},
{
header0: datacel4,
header1: datacel5,
header2: datacel6,
header3: datacel7,
}
];
I am getting output like below all the objects are same or overridding
[
{
header0: datacel60,
header1: datacel61,
header2: datacel62,
header3: datacel63,
},
];