JavaScript Array Methods – Complete Guide

Here’s a list of commonly used array methods in JavaScript. Each method includes a simple explanation and an example.

Array Methods Reference Table

MethodWhat It DoesExample
concat()Combines two or more arrays into one new array.
let a = [1, 2];
let b = [3, 4];
let c = a.concat(b); // [1, 2, 3, 4]
every()Returns true if all elements pass a test.
[2, 4, 6].every(x => x % 2 === 0); // true
filter()Creates a new array with elements that pass a test.
[1, 2, 3, 4].filter(x => x > 2); // [3, 4]
forEach()Runs a function for each element in the array.
["a", "b", "c"].forEach(x => console.log(x));
indexOf()Returns the index of the first match, or -1 if not found.
["a", "b", "c"].indexOf("b"); // 1
join()Joins all elements into a string with a separator.
[1, 2, 3].join("-"); // "1-2-3"
lastIndexOf()Finds the last matching index of a value.
[1, 2, 1, 3].lastIndexOf(1); // 2
map()Creates a new array with the result of a function for each element.
[1, 2, 3].map(x => x * 2); // [2, 4, 6]
pop()Removes the last item and returns it.
let arr = [1, 2, 3];
arr.pop(); // 3
push()Adds an item to the end and returns new length.
let arr = [1, 2];
arr.push(3); // 3, arr is now [1, 2, 3]
reduce()Reduces the array to a single value.
[1, 2, 3].reduce((a, b) => a + b); // 6
reduceRight()Like reduce(), but from right to left.
["a", "b", "c"].reduceRight((a, b) => a + b); // "cba"
reverse()Reverses the order of elements in the array.
[1, 2, 3].reverse(); // [3, 2, 1]
shift()Removes the first item and returns it.
let arr = [1, 2, 3];
arr.shift(); // 1
slice()Returns a piece of the array (does not change the original).
[1, 2, 3, 4].slice(1, 3); // [2, 3]
some()Returns true if any item passes the test.
[1, 3, 5].some(x => x % 2 === 0); // false
sort()Sorts elements alphabetically by default.
[3, 1, 2].sort(); // [1, 2, 3]
splice()Adds/removes items from any index.
let arr = [1, 2, 3];
arr.splice(1, 1, 9); // arr = [1, 9, 3]
toString()Converts array to a comma-separated string.
[1, 2, 3].toString(); // "1,2,3"
unshift()Adds items to the start and returns new length.
let arr = [2, 3];
arr.unshift(1); // arr = [1, 2, 3]