The traversal was achieved with the function:
transformEmployeeData2(array) {
var obj = {};
var final = [];
var arrayJson = JSON.parse(JSON.stringify(array));
for (var i = 0; i < arrayJson.length; i++) {
obj = {}; // <-- Se limpia la variable objeto para que no almacene más de una referencia
var general = array[i];
for (var n = 0; n < general.length; n++) {
var data = general[n];
var first = data.shift();
var last = data.pop();
obj[first] = last;
}
final.push(obj);
}
console.log(final);
}
To loop through
Array
you would do it this way:I hope you find it useful.