Java Script arrays
Java Script arrays are used to store multiple values in a single variables . It may single value or collection of objects . Arrays are very important in Java Script. Let us look how can we create arrays in Java Script.
we can create Java script arrays as follows .
var subjects=["Telugu","Tamil","Hindi","English "] ;
we can also create Java script arrays as follows
var subjects=[]; this indicates an empty array with the name of subjects;
let us add some values for the arrays . Arrays value positions are started from 0 . It means in the above example the index (position ) of the Telugu is "0", and Tamil is "1",
so we can add the values for the array in as follows.
subjects[0]="Telugu";
subjects[1]="Tamil";
How can we retrieve or Iterate the Data from an array ?
we can do it in two different methods . The first way of doing this is by using the for loop . First wee need to find out the no of values inside the array . By using the "length" method we can do it
Example: subjects.length will give you the no of values inside the array .
Once we found the no of values in the array, with help of for loop we can iterate the array as follows;
for (var i=0; i<subjects.length;i++){
console.log(subjects[i]);
}
How the for loop works?

Comments