-
What arrays allow us to do?
The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, specifically a collection of variables of the same type.
The Array parameter is a list of strings or integers. When you specify a single numeric parameter with the Array constructor, you specify the initial length of the array. The maximum length allowed for an array is 4,294,967,295. You can create array by simply assigning values as follows −−> var fruits = [“apple”, “orange”, “mango”]; and using ordinal numbers to access and to set values inside an array as in:
- fruits[0] is the first element
- fruits[1] is the second element
- fruits[2] is the third element
-
What index should you use in order to access the first element in an array?
JavaScript array indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present. By default array index starts from zero so index [0] is the first element.