14TH DAY AT UKI
ARRAY
1. Javascript arrays are used to store multiple values in a single variable.
Example:
var cars=["saab","volvo","BMW"]
1. Javascript arrays are used to store multiple values in a single variable.
Example:
var cars=["saab","volvo","BMW"]
2. We refer to an array element by referring to the index number.
Example:
var cars=["saab","volvo","BMW"]
document.getElementById("demo").innerHTML=cars[0];
result is saab
3. Array indexes starts with 0.
4. Arrays are a special type of objects.
5. Length property
The length property returns the number of elements.
Example:
var fruits=["banana","orange","apple","mango"];
fruits.length;
result is 4
For Loop
1.Loops are handy, if you want to run the same code over and over again, each time with a different value.
for(statement1;statement2,statement3)
{
code block to be executed
}
Example:
for(i=0;i<5;i++)
{
text+="The number is"+i+"<br>";
}
2.Statement1
Normally you will use statement 1 to initialize the variable used in the loop (i = 0).
This is not always the case, JavaScript doesn't care. Statement 1 is optional.
3.Statement2
Often statement 2 is used to evaluate the condition of the initial variable.
4.Statement3
Often statement 3 increments the value of the initial variable.
statement3 is optional.
Example:
var cars=["saab","volvo","BMW"]
document.getElementById("demo").innerHTML=cars[0];
result is saab
3. Array indexes starts with 0.
4. Arrays are a special type of objects.
5. Length property
The length property returns the number of elements.
Example:
var fruits=["banana","orange","apple","mango"];
fruits.length;
result is 4
For Loop
1.Loops are handy, if you want to run the same code over and over again, each time with a different value.
for(statement1;statement2,statement3)
{
code block to be executed
}
Example:
for(i=0;i<5;i++)
{
text+="The number is"+i+"<br>";
}
2.Statement1
Normally you will use statement 1 to initialize the variable used in the loop (i = 0).
This is not always the case, JavaScript doesn't care. Statement 1 is optional.
3.Statement2
Often statement 2 is used to evaluate the condition of the initial variable.
4.Statement3
Often statement 3 increments the value of the initial variable.
statement3 is optional.
No comments:
Post a Comment