JavaScript Basic Array Methods
Author: Dustin Usey
Date: October 17, 2022
Arrays are used to store a collection of multiple items under a single variable name. This collection could be things like strings, numbers, or even a mix of different data types. Sometimes we need to update or manipulate our arrays by adding or removing items, or combining one array with another. In this guide, we’ll discuss some of the many basic JavaScript array methods.
JavaScript arrays are versatile data structures that allow you to store multiple values in a single variable. This guide covers some essential array methods that enable you to manipulate and work with arrays effectively.
To deepen your understanding of JavaScript arrays, you can check out the following resources:
The .push()
method adds one or more elements to the end of an array.
The .pop()
method removes the last element from an array and returns that element.
The .shift()
method removes the first element from an array and returns that removed element.
The .unshift()
method adds one or more elements to the beginning of an array.
The .indexOf()
method returns the first index at which a given element can be found in the array, or -1 if it is not present.
The .toString()
method converts an array to a string of comma-separated values.
The .join()
method joins all elements of an array into a string, with an optional separator.
The .concat()
method combines two or more arrays.
Additional resources for specific methods:
- MDN – .length()
- MDN – .push()
- MDN – .pop()
- MDN – .shift()
- MDN – .unshift()
- MDN – .indexOf()
- MDN – .toString()
- MDN – .join()
- MDN – .concat()
For further exploration of JavaScript array methods, you can refer to the following resources:
Special thanks to Team Treehouse. Team Treehouse offers comprehensive courses on JavaScript and web development. Check out their JavaScript Arrays course for a deeper understanding of array manipulation in JavaScript.