An Easy Way to Understand JavaScript Array Methods

Common JavaScript array methods with easy explanations

This is an interesting article just because of the image, that is explaining all the methods. Just go through the article once and have a look at the above image. You will definitely have very few to zero doubts left.

1. Map

One of the most used array methods in JavaScript. This is a useful method that you can use for hundreds of purposes. Suppose you need only names from the whole array of objects. You can mention which item you need, and that’s it. Converting one array into another is also possible by this method.

2. Filter

Sometimes we need to find things within some conditions. Let us assume that we want to get all the items equal to or less than 100, then all we need to use is the filter method. Here is an example below. This filter method will only return an array of objects where your condition is true.

3. The find method

The find method will help us to find an object within an array. This is also like the previous method. Just replace the map with the find method, then mention the condition that you’re looking for/finding in the array. The function will return only the first match. You can also find someone by age in the below example.

4. FindIndex

The findIndex() method returns the index of the first element in an array that passes a test (provided as a function).

5.Fill

The fill() method changes all elements in an array to a static value, from a start index (default 0) to an end index (default array.length). It returns the modified array.

6. Some

The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns true if, in the array, it finds an element for which the provided function returns true; otherwise it returns false. It doesn’t modify the array.

7. Every

The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.

Conclusion

In this article, I tried to cover all the potentially useful JavaScript array methods. I hope this article will be helpful for your daily use. If I missed something, don’t forget to mention it in the comments. I will update the article accordingly.

Have a great day!

Leave a Reply

Your email address will not be published. Required fields are marked *