DEV Community


An Introduction to Helpful Array Methods

seandershancevic profile image Seanders-Hancevic ・2 min read

I'm not an expert on coding by any means, in fact, I'm currently enrolled in a full-stack development course which I am only in the middle of. That being said, there were a few useful things I learned about arrays and how to deal with the data stored inside of them. However, this post is just about array methods. The first thing i learned about array methods is that the methods will loop through the array for you, searching for data based on the method you used. This means we don't need to use 'for' loops to loop through the entire array, the methods will do it for us.

The first one is the forEach() array method. This method goes through the entire array and basically grabs each element on the array and then you can perform different actions with that data.

The next one is the filter() method. This one allows us to filter data out from the array based on the specifications we give it.

Another useful method is the includes() method. This loops through the array and finds any element with the parameters you specify, similar to the filter() method.

There is push() which allows you to add new elements to the end of an array. This can be useful for making lists of any kind.

Finally, splice() is a very useful method because it allows to either "splice" and element into the array, or add it, but it can also delete items or "splice" them out in the same fashion.

These are just a few of the different types of array methods out there, but these are a few I found particularity helpful!

Discussion (0)

Forem Open with the Forem app