Site icon Tutorial

Arrays object and methods

Arrays – It is an ordered collection of values with each value is called an element, having a numeric position in the array called its index. JavaScript arrays may be of any type and elements of the same array can be of different types.

Array creation – An array is created with a comma-separated list of elements within square brackets. Array can be empty with no elements or with elements as

var blank = []; // Empty array

var odd = [1, 3, 5, 7]; // Array with elements

Array object – Another way to create an array is with the Array() constructor by calling it with

Element access – To access an element of array use the [] operator with array name and index in the square brackets as arrayname[index]. This form can be used to read or write value at the specified index.

Array methods – Various array methods are discussed below:

Back to Tutorial

Exit mobile version