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];
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With