I've a javascript object inside a variable data
like:
data: Object {
aliquota: 23,
imponibileLordo: 300,
imponibileScontato: "",
imposta: 69
}
In another function i've to iterate the object using an index like:
for ( var index = 0; index < data.length; index++ ) {
var valueOfIndex = data[index];
console.log(valueOfIndex);
}
But I get error cause data[0], data[1], data[2], data[3] are not defined.
How can solve this? Important: i've to use a numeric INDEX for cycle for cause I do other operation based on index value.
UPDATE: Ok my goal is another. So i'll upload the script i'm using with the fix I DON'T LIKE but works. (See //ACTUAL FIX
comment) Also the fiddle here: https://jsfiddle.net/am3ovL3b/5/
var array_iva = [];
var data = { "impo": 10, "aliq": 20, "other": 30 };
var column = { "title": "TEST 1", "data": data };
array_iva.push(column);
var data = { "impo": 40, "aliq": 50, "other": 60 };
var column = { "title": "TEST 2", "data": data };
array_iva.push(column);
var json_righe = [[ "Imponibile lordo" ], [ "Aliquota %" ], [ "Others" ] ];
for ( var i = 0; i < array_iva.length; i++ ) {
var titolo_colonna_iva = {};
titolo_colonna_iva['title'] = array_iva[i]['title'];
for ( j = 0; j < json_righe.length; j++ ) { // for each
var riga = json_righe[j];
for ( var k = 0; k < array_iva.length; k++ ) { // EMPTY DEFAULT
riga.push("");
}
// ACTUAL FIX
if ( j == 0 ) {
riga[(i+1)] = array_iva[i]['data']['impo'];
} else if ( j == 1 ) {
riga[(i+1)] = array_iva[i]['data']['aliq'];
} else if ( j == 2 ) {
riga[(i+1)] = array_iva[i]['data']['other'];
}
//END ACTUAL FIX
/*
THIS DOESn?T WORK
riga[(i+1)] = array_iva[i]['data'][j];
*/
json_righe[j] = riga;
}
}