As you all know, normally a variable can hold only one piece of data at a time. But Arrays are special because it can hold more than one value at a time, and you can access these values individually.
If you already know the number of items that would store in an array, you can pass the number to the constructor of an Array Object
The above array declaration creating an Array using the Constructor, that holds 10 undefined elements. Similarly, you can directly initialize the Array elements when declaring an Array Object.
You can display Array elements in several ways. The following methods will show all elements from an Array.
The above statement will return undefined, because weekArray does not exists.
Accessing Array elements using for loop
Array element types
In the above declaration genericArray stores String, Numeric, Boolean and Object.
The above statement will return 7, that means the weekArray contains seven elements.
If you specified the length while creating the array, this will return as length property's value.
Arrays Undefined Values
Arrays are automatically growing and dynamically sized to accommodate any type of data that is added to them. So, when you add or remove elements from an array, the length of the array will change as needed. When you declare an Array with constructor, each slot will be set to "undefined".
The above code will return Red, Green, Blue , Yellow, that is Yellow added at the end of the Array
The Array.Contains() method checking whether or not an item is contained within your array.
The array order will be...Monday, Sunday, Tuesday.
The array order will be...Tuesday, Sunday, Monday
The array order will be..30, 40, 50, 80
The array order will be..80, 50, 40, 30
colors.splice(2,0,"Yellow","Orange") means that add new elements at the array index 2 and removed 0 elements.
The array order will be ...Red, Blue, Yellow, Orange, Green
The selectedColors are...Blue,Green.
colors.slice(1, 3) select 1 to 3-1 elements from colors.
The result will be Red#Blue#Green
The result will be RedBlueGreen