DEV Community

cisneros-a
cisneros-a

Posted on

Different Array Methods (pt. 4)

We'll be going over a few more Array methods this week.

Array.lastIdexOf()

Alt Text

What it does:

This method will look for the last instance of whatever you pass in as an argument to the method. You see in our example, we are looking for the number 3.

What it returns:

This method returns the index of the last instance that matches what you passed in as argument. We see that 3 is in the array twice, but the last instance of it is at the 3rd index.

Array.toString()

Alt Text

What it does:

This method does exactly what you think it will. It will stringify the array.

What it returns:

This will return the contents of the array as a string. Even if there are nested arrays.

Array.forEach()

Alt Text

What it does:

This method will execute a callback function for each item in the array. However, we usually avoid this in favor of the .map method, which returns an array.

What it returns:

The forEach method will always return undefined.

Top comments (0)