So I started with importing 4 different arrays with equal amounts of data.
Then I made a class, thinking the class can help me make the objects, with that imported data.
So my thinking was if I loop through that class, it can make an object that contains the data of all 4 arrays by its index, and then push that object into an array.
I was hoping my ending results for objectArray would look like...
[ {nn: "Lion", dat1: 4, dat2: 9, dat3: 10}, {nn: "Zebra", dat1: 5, dat2: 10, dat3: 7}, {nn: "Monkey", dat1: 2, dat2: 6, dat3: 14} ...etc. ]
// mock
const threeToType = {
name: ["Lion", "Zebra", "Monkey"],
data1: [ 4, 5, 2],
data2: [ 9, 10, 6],
data3: [ 10, 7, 14],
};
const {name, data1, data2, data3} = threeToType; // require('./threeToType');
let objectArray = [];
class makeObj{
constructor(nn, dat1, dat2, dat3){
this._nn = nn;
this._dat1 = dat1;
this._dat2 = dat2;
this._dat3 = dat3;
}
}
for(let newObj, i = 0, tN = "", tD1 = 0, tD2 = 0, tD3 = 0; i<name.length; i++){
tN = name[i];
tD1 = data1[i];
tD2 = data2[i];
tD3 = data3[i];
objectArray.push(newObj = new makeObj(tN, tD1, tD2, tD3));
}
console.log(objectArray);