Working with Array

An array is a collections of value. all wrapped up, and have a name.

We know that we can create variable that has name and one value. Now, array is the idea of multiple value but all contain in one named variable.

var myArray = [x, 123, 1/1/2011, "hello", true]

We have a variable called myArray that have multiple value inside it. We don't have to name every single value or element, we just have to contain them in one variable.

In Javascript, you can make an array with multiple value from different data type like in example above. Each element have index value that identifies where it is in array. Array is zero-based index. That means first element in array have index of 0, the second element have index of 1 and so on. You use that index to get value we store.

var myArray = [x, 123, 1/1/2011, "hello", true];

var a;
a = myArray[0]  //a now have value of x
a = myArray[1]  //a now have value of 123
a = myArray[3]  //a now have value of "hello"

results matching ""

    No results matching ""