Top 10 JavaScript Array Methods You Should Know

In this post, I will share 10 JavaScript array methods you should know. If you know nothing about array, you can click here for array. Here are 10 javascript array methods you should at least know.

1. forEach()

This method can help you to loop over an array’s items.

const arr = [1, 2, 3, 4, 5, 6];

2. includes()

This method checks if the array includes the item passed in the method.

const arr = [1, 2, 3, 4, 5, 6];

arr.includes(2); // output: true
arr.includes(7); // output: false

3. filter()

This method creates a new array with only elements passed condition inside the provided function.

const arr = [1, 2, 3, 4, 5, 6];

4. map()

This method creates a new array by calling the provided function in every element.

const arr = [1, 2, 3, 4, 5, 6];

5. reduce()

The reduce() method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value — MDN

const arr = [1, 2, 3, 4, 5, 6];

const sum = arr.reduce((total, value) => total + value, 0);
console.log(sum); // 21

6. some()

This method checks if at least one of the array’s items passed the condition. If passed, it returns ‘true’ otherwise ‘false’.

const arr = [1, 2, 3, 4, 5, 6];

7. every()

This method checks if all array items passed the condition. If passed, it returns ‘true’ otherwise ‘false’.

const arr = [1, 2, 3, 4, 5, 6];

8. sort()

This method is used to arrange/sort the array’s item in either ascending or descending order.

const arr = [1, 2, 3, 4, 5, 6];
const alpha = ['e', 'a', 'c', 'u', 'y'];

9. Array.from()

This change all thing that is array-like or iterable into true array especially when working with DOM, so that you can use other array methods like reduce, map, filter and so on.

const name = 'frugence';
const nameArray = Array.from(name);

10. Array.of()

This creates an array from every argument passed into it.

const nums = Array.of(1, 2, 3, 4, 5, 6);
console.log(nums); // output: [1, 2, 3, 4, 5, 6]

--

--

I'm a student I always like to learn new things and have experience with new stuff. I'm trying to be more creative and will come back soon with something unique

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
Abdur Rahman

I'm a student I always like to learn new things and have experience with new stuff. I'm trying to be more creative and will come back soon with something unique