Obviously, this is not allowed in javascript:
for (var i=0; i<data.length; i++){
array[i].push(data[i].name);
}
Does anyone know of a workaround that does the same thing?
Obviously, this is not allowed in javascript:
for (var i=0; i<data.length; i++){
array[i].push(data[i].name);
}
Does anyone know of a workaround that does the same thing?
You can do
for (var i=0; i<data.length; i++){
array[i] = [];
array[i].push(data[i].name);
}
but Alexey Ayzin, shurely this is the better alternative - create a single array, push the desired values into it and then access it via normal means::
arrayTest = [];
for (var i=0; i<data.length; i++){
arrayTest.push(data[i].name);
}
This will give arrayTest all names, and can be accessed as:
var testName=arrayTest[3];
Doing it the other way will give you lots of unnamed arrays - how are they to be used?