How would you reference a value in a Javascript object without the key?
So, given the object:
var JSONdata= [
{"index":"1","var1":1,"var2":2},
{"index":"2","var1":3,"var2":2},
{"index":"3","var1":3,"var2":1},
{"index":"4","var1":2,"var2":1},
{"index":"5","var1":1,"var2":3},
];
Say I want to reference the values of var1 and var2 in a loop, but the names "var1" and "var2" change and the number of variables also changes.
So in Pseudocode:
while ( i < JSONdata.length ) {
for (j = 1 to Num_variables) {
Give me the value for varN
next j
}
i++
}
Thanks
index
property but include all other properties of each object?index
variable is my x-axis, then I want to loop through every other variable. The answers below are right on.