JavaScript For Kids For Dummies
Book image
Explore Book Buy On Amazon

Array methods in JavaScript are built-in things that can be done with or to JavaScript arrays. These methods are perhaps the best part about working with arrays in JavaScript. Once you know how to use them, you’ll save yourself a lot of time and effort. Plus, they can also be a lot of fun!

JavaScript’s built-in array methods are listed here.

JavaScript Array Methods
Method Description
concat() A new array made up of the current array, joined with other array(s) and/or value(s).
indexOf() Returns the first occurrence of the specified value within the array. Returns –1 if the value is not found.
join() Joins all the elements of an array into a string.
lastIndexOf() Returns the last occurrence of the specified value within the array. Returns –1 if the value is not found.
pop() Removes the last element in an array.
push() Adds new items to the end of an array.
reverse() Reverses the order of elements in an array.
shift() Removes the first element from an array and returns that element, resulting in a change in length of an array.
slice() Selects a portion of an array and returns it as a new array.
sort() Returns an array after the elements in an array are sorted. (The default sort order is alphabetical and ascending.)
splice() Returns a new array comprised of elements that were added to or removed from a given array.
tostring() Converts an array to a string.
unshift() Returns a new array with a new length by the addition of one or more elements.

About This Article

This article is from the book:

About the book authors:

Chris Minnick and Eva Holland are experienced web developers, tech trainers, and coauthors of Coding with JavaScript For Dummies. Together they founded WatzThis?, a company focused on training and course development.

This article can be found in the category: