We'll be going over a few more Array methods this week.
Array.lastIdexOf()
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()
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()
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)