I have to make this addRows method with some data, which needs following construction.
data.addRows([
['UK', 10700,100],
['USA', -15400,1]
]);
But i have only this way data coming, how can i make it for above method?
var custom = new Array();
success : function(msg)
{
/* Make this structure
[
['UK', 10700,100],
['USA', -15400,1]
]
*/
var total = parseInt(msg.total);
for(i=0; i < total; i++ ) {
custom[0][i][0] = msg.rows[i].land;
custom[0][i][1] = msg.rows[i].id;
custom[0][i][2] = msg.rows[i].id;
}
}
data.addRows(custom); // does not work
Error: (tried 3 examples all return same)
Uncaught TypeError: Cannot call method 'toString' of null
Uncaught TypeError: Cannot read property 'land' of undefined
The
splicemethod can be used to add elements to an array en masseOr you could add something like this to Array’s prototype:
DEMO