Home

Working with Array Methods in JavaScript

|
|  Updated:  
2016-03-26 07:26:12
JavaScript Essentials For Dummies
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 author:

Chris Minnick is an accomplished author, teacher, and programmer. Minnick authored or co-authored over 20 books, including titles in the For Dummies series. He has developed video courses for top online training platforms and he teaches programming and machine learning to professional developers at some of the largest global companies.

Eva Holland is an experienced web developer, tech trainer, and coauthor of Coding with JavaScript For Dummies. She is a co-founder of WatzThis?, a company focused on training and course development.