10 JavaScript Array Methods as Simple as Possible

How to become a master of JavaScript arrays

Deepak Gangwar
Frontend Weekly
3 min readAug 3, 2020

--

Photo by Clément H on Unsplash

As a front end developer, learning JavaScript is scary. And if you are anything like me, you don’t know where to go, where to start. Thousands of resources to choose from which just makes us anxious and not learn anything. Here is something that helped me get better at the arrays. Hope it helps you too.

If you want to know more about JavaScript functions, you can read this short article.

JavaScript array is a special type of variable that lets you store multiple values just like a list.

Most programming languages have arrays, but the difference in JavaScript arrays is that you can store different data types in an array which is not possible in other programming languages.

1. Push

The push() method adds a new element at the end of an array and returns new length. To add items in the beginning use unshift. This can be used in adding an item to a to do list.

2. Slice

The slice() method selects a part of an array, and returns the new array. It is very similar to slicing bread. Remember array index starts from 0. So myArray.slice(1,2) means you want to make a cut in the bread loaf at positions 1 and 2. That will give you the middle part of what lies between positions 1 and 2.

3. Tostring

The tostring() method converts an array to a string, and returns the result.

4. Shift

The shift() method removes the first element of an array, and returns that remaining.

5. Unshift

The unshift() method adds an element at the beginning of an array.

6. Map

The map() method creates a new array with the results of calling a function for every array element.

7. Pop

The pop() method pops off (removes) the last element of an array, and returns the last element.

8. Filter

The filter() method creates an array filled with all array elements that pass a test (provided as a function).

9. Includes

The includes() method determines whether an array contains a specified element. It returns boolean true or false.

10. Length

This is the most basic one. The length() method gives the number of elements present in an array.

The Conclusion

JavaScript can be daunting, especially if you are a beginner. But some simple guides can help us reduce the anxiety we get during the learning process. These are the ten JavaScript array methods for you. This helped me in my learning journey. And I believe it will be of importance to you, too.

Further if you want to know more about JavaScript functions, you can read this short article.

--

--

Deepak Gangwar
Frontend Weekly

Independent designer x developer (P.S. not verified on Twitter). Subscribe to my free newsletter for more valuable content - https://deepakgangwar.beehiiv.com