Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store javascript variable into array [duplicate]

Tags:

Is it possible to store variables into arrays? What is the correct way of doing it? I can't seem to be able to store it in this way.

var fxVal = '<?php echo $fxVal;?>'; var equitiesVal = '<?php echo $equitiesVal;?>'; var boVal = '<?php echo $boVal;?>'; var balance = '<?php echo $account_balance;?>';  var myData = [fxVal,equitiesVal,boVal,balance]; 
like image 716
user2735129 Avatar asked Aug 31 '13 08:08

user2735129


People also ask

Can you store variables in an array JavaScript?

To overcome this problem, JavaScript provides an array. An array is a special type of variable, which can store multiple values using special syntax. Every value is associated with numeric index starting with 0. The following figure illustrates how an array stores values.

Does JavaScript array allow duplicates?

Using Array.If any item in the array, both indices don't match, you can say that the array contains duplicates. The following code example shows how to implement this using JavaScript some() method, along with indexOf() and lastIndexOf() method. Output: Duplicate elements found.


1 Answers

There are several ways to do it:

var array1 = [var1, var2, var3, var4]; var array2 = new Array(var1, var2, var3, var4); 

or

var array3 = new Array;  array3.push(var1); array3.push(var2); array3.push(var3); array3.push(var4); 
like image 137
cl0udw4lk3r Avatar answered Oct 26 '22 23:10

cl0udw4lk3r