JavaScript Array
JavaScript Array is a way to 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, but it is often more useful to think of an array as a collection of variables of the same type.
Here is the syntax of JavaScript array:
Syntax:
var array_name = [item1, item2, ...];
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 −
JavaScript Keyword new
You can also create an array using new keyword.
JavaScript Array Method
Here is a list of methods of JavaScript array:
Methods | Description |
---|---|
concat() | Returns a new array object that contains two or more merged arrays. |
copywithin() | Copies the part of the given array with its own elements and returns the modified array. |
every() | It determines whether all the elements of an array are satisfying the provided function conditions. |
fill() | It fills elements into an array with static values. |
filter() | It returns the new array containing the elements that pass the provided function conditions. |
find() | It returns the value of the first element in the given array that satisfies the specified condition. |
findIndex() | It returns the index value of the first element in the given array that satisfies the specified condition. |
forEach() | It invokes the provided function once for each element of an array. |
includes() | It checks whether the given array contains the specified element. |
indexOf() | It searches the specified element in the given array and returns the index of the first match. |
join() | It joins the elements of an array as a string. |
lastIndexOf() | It searches the specified element in the given array and returns the index of the last match. |
map() | It calls the specified function for every array element and returns the new array. |
pop() | It removes and returns the last element of an array. |
push() | It adds one or more elements to the end of an array. |
reverse() | It reverses the elements of given array. |
shift() | It removes and returns the first element of an array. |
slice() | It returns a new array containing the copy of the part of the given array. |
sort() | It returns the element of the given array in a sorted order. |
splice() | It add/remove elements to/from the given array. |
unshift() | It adds one or more elements in the beginning of the given array. |