JavaScript Array Methods

Code Result
concat
Joins two or more arrays and returns a new array with all the items.

            
indexOf
Locates the item in the array and returns its index.

            

            
join
Creates a string from the items in the array. The items are comma-delimited by default, but you can pass an alternate separator.

            

            
lastIndexOf
Searches from the end of the array for the last item in the array that meets the search criteria and returns its index.

            

            
pop
Removes and returns the last element of the array. This reduces the length of the array by one.

            

            
push
Adds a new item to the end of an array and returns the new length.

            

            
reverse
Reverses the order of the items in an array and returns a reference (not a new array) to the reversed array, so the original array is modified.

            

            
shift
Removes and returns the first item in the array. If no items are in the array, the return value is undefined.

            

            
slice
Returns a new array that represents part of the existing array. The slice method has two parameters: start and end. The start parameter is the index of the first item to include in the result. The end parameter is the index of the item that you don't want included in the result.

            

            
sort
Sorts the items in an array and returns a reference to the array. The original array is modified.

            

            
splice
Adds and removes items from an array and returns the removed items. The original array is modified to contain the result. The splice method's first parameter is the starting index of where to start adding or deleting. The second parameter indicates how many items to remove. If 0 is passed as the second parameter, no items are removed. If the second parameter is larger that the quantity of items available for removal, all items from the starting index to the end of the array are removed. After the first two parameters, you can specify as many items as you want to add.

            

            
toString
All objects have a toString method. For the Array object, toString creates a string from the items in the array. The items are comma-delimited, but if you want a different delimiter, you can use the join method and specify an alternate separator.

            

            
unshift
Adds a new item to the beginning of an array and returns the new length.

            

            
valueOf
All objects have a valueOf method. For the Array object, valueOf returns the array.