In JavaScript, can I put a variable into the array brackets?
Hi,
So for instance,
if i have
var num1=new Array();
num10=//something;
num11=//something;
num12=//something;
will i just do this to cause it to easier as to which variety piece I am using
Example:
insurance coverage.write(num1 shifting in in this article );
Thanks beforehand!
-JDDellGuy
Yes, that you can do this
You could also start using a loop for you to traverse through each of the values inside array
For instance
for(i =0; i<array.Duration; i++)
insurance coverage.write(num1i);
It is equivalent in order to
insurance coverage.write(num10);
insurance coverage.write(num11);
insurance coverage.write(num12);
insurance coverage.write(num13);……
But be careful not to use your integer which can be out of your bounds on the array.
You can not use every integer around num1variable.
The integer Must be within that bounds belonging to the array
When var new1 = brand new Array(10);
in that case, new111; can be invalid and even new110 is invalid
mainly because new10 —– new19 will probably hold TEN values
Indeed, JDDellGuy, you are able to assign your variable having an “if” assertion.
var X=prompt(“Enter purple, green, or blue”);
var new_X; // A new variable that can store the phone number in it
when (X==”red”)
new_X=0;
altogether different if (X==”green”)
new_X=1;
altogether different if (X==”blue”)
new_X=2;
insurance coverage.write(num1new_X);
This may do
Thanks expectation this helps
Yes providing the variable is definitely an integer all this is executed in loops every one of the time.
var d = YOUR FIVE;
numn = A FEW; // identical to writing num5 = SOME;
Leave a Reply
You must be logged in to post a comment.