views:

218

answers:

4

Hi, I'm relatively new to JavaScript and I've been having trouble pushing data into an array.

I have two dynamic vars and I need the array to be formatted like:

var array = [[-373597200000, 315.71], [-370918800000, 317.45], [-368326800000, 317.50]];

I already have a loop running for each iteration of the vars, I'm just not sure how I put the two vars into the array in the format above. I've tried:

array.push(var1 + "," + var2);

For each iteration of the loop but it doesn't seem to be working.

So, what's the proper way to push data into an array in the format above?

Thanks in advance!

+2  A: 
array.push([var1,var2]);
Nosredna
+3  A: 

Your array contains other arrays as elements, you need to add another array, not a string:

array.push([var1, var2]);

More info:

CMS
Thanks for the extra information, it's very helpful.
John Jones
+1  A: 
array.push([var1,var2])
Jonathan Feinberg
A: 

var a = new Array(); a.push('Test');

output :

["Test"]

Actually I tried your example it worked for me

var a = new Array(); var var1 = "Test1"; var var2 = "Test2"; a.push(var1 + " "+ var2); a;

output : ["Test1 Test2"]

Summy