I have retrieved an array of objects from a csv file and it looks like the following when printed:
Array[4]
0:Object
value1:"200"
value2:"95"
value3:"6395"
value4:"2"
1:Object
2:Object
3:Object
The process I used to create this array is as follows:
var strCSV = e.target.result;
var arrCSV = strCSV.match(/[\w .]+(?=,?)/g);
var noOfCols = 4;
// Ignoring the header row
var hdrRow = arrCSV.splice(0, noOfCols);
var data = [];
while (arrCSV.length > 0) {
var obj = {};
var row = arrCSV.splice(0, noOfCols)
for (var i = 0; i < row.length; i++) {
obj[hdrRow[i]] = row[i].trim();
}
data.push(obj)
}
Now if I want to create another array with the same data but different keys, like so:
var tableData = [
{key1: "", key2: "", key3: "", key4: ""}];
I have attempted various methods to achieve this but haven't been successful. For example, I tried the following approach:
for(var i=0; i<data.length; i++){
tableData[i]["key1"] = data[i].value1;
}
Creating an empty array thinking that adding elements on the go would work, but it did not. Is there a way to accomplish this without manually copying each element from the original array?