Just when I think I'm getting an understanding of the syntax of Javascript, I run into something like this...
I saw this code on the jqPlot plugin page.
what kind of array is [[]] in javascript? A nested array? I thought I understood the double brackets, but in the commented text, I don't understand why there is an extra set (question below).
$(document).ready(function(){
// Our data renderer function, returns an array of the form:
// [[[x1, sin(x1)], [x2, sin(x2)], ...]]
var sineRenderer = function() {
var data = [[]];
for (var i=0; i<13; i+=0.5) {
data[0].push([i, Math.sin(i)]);
}
return data;
};
Why is there an extra set of brackets in this commented statement (the outermost set)?
[[[x1, sin(x1)], [x2, sin(x2)], ...]]
Thanks
[[],[],[]]is the syntax for an array that contains other arrays. Each inner array in your example contains a number and the sine function of that number.