Most Common JavaScript Array Methods

In JavaScript, Array is a single variable that is used to store different elements. Basically there are two ways to declare an array in JavaScript.

var cars = [];
var cars = new array();

In this article, I am going to mention mostly common array methods used in JavaScript.


This method is used to merge two or more arrays. This doesn’t modify the existing array, but returns a new array.

const arr1 = ['Lamborghini', 'Audi', 'Mercedes-Benz'];
const arr2 = ['Ford', 'Toyota'];
const cars = arr1.concat(arr2);
//output: ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota']


This method creates a new array with all elements that pass the test implemented by the provided function.

const cars = ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota'];const result = cars.filter(car => car.length < 5);console.log(result);
//output: ['Audi', 'Ford']


This method returns the value of the first element in the provided array that satisfies the provided testing function.

const cars = ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota'];const result = cars.find(car => car.length < 5);console.log(result);
//output: 'Audi'


This method executes a provided function once for each array element.

const cars = ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota'];cars.forEach(car => console.log(car));//output: 'Lamborghini'
//output: 'Audi'
//output: 'Mercedes-Benz'
//output: 'Ford'
//output: 'Toyota'


This method determines whether an array includes a certain value among its entries, and returns true or false.

const cars = ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota'];console.log(cars.includes('Ford'));
//output: true
//output: false


This method returns the first index at which a given element can be found in the array, or -1 if it is not present.

const cars = ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota'];console.log(cars.indexOf('Lamborghini'));
//output: 0
//output: -1


This method creates a new array populated with the results of calling a provided function on every element in the calling array.

const arr = [1, 2, 3, 4, 5];const result = => e * 5);console.log(result);
//output: [5, 10, 15, 20, 25]


This method removes the last element from an array and returns that element.

const cars = ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota'];console.log(cars.pop());
//output: 'Toyota'
//output: ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford']


This method adds one or more elements to the end of an array and returns the new length of the array.

const cars = ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota'];console.log(cars.push('Bugatti'));
//output: 6
//output: ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota', 'Bugatti']


This method reverses an array in place . The first array element becomes the last, and the last array element becomes the first.

const cars = ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota'];console.log(cars.reverse());
//output: ['Toyota', 'Ford', 'Mercedes-Benz', 'Audi', 'Lamborghini']


This method removes the first element from an array and returns that removed element.

const cars = ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota'];console.log(cars.shift());
//output: 'Lamborghini'
//output: ['Audi', 'Mercedes-Benz', 'Ford', 'Toyota']


This method sorts the elements of an array in place as ascending and returns the sorted array.

const cars = ['Lamborghini', 'Audi', 'Mercedes-Benz', 'Ford', 'Toyota'];
//output: ['Audi', 'Ford', 'Lamborghini', 'Mercedes-Benz', 'Toyota']

In this article, I’ve briefly mentioned mostly used array methods in JavaScript and there are some more methods which helps to manipulate data in arrays. You can refer them by visiting,

Thanks for reading!

Open Source Enthusiast🖤 | JavaScript Developer👨🏻‍💻 | Undergraduate — Software Engineering🧑🏻‍💻 | SLIIT👨🏻‍🎓

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store