JavaScript Array Methods

Natalia Wit
3 min readSep 6, 2020

Array.prototype.filter()

This method returns a new array containing all of the elements from the original array once it meets the condition to be equal to true. It will return all of the elements you are looking for as long as it exists in the original array. Below is an example of how the method works with an output that meets my testing condition.

Filter() will return an array of fruits from the original that is equal to “peach”

Array.prototype.filter()

This find() method returns the value of the first element in the provided array that satisfies the provided testing function. Otherwise, an unidentified is returned. In the below example you will see that undentified was returned for every time I declared a variable only because nothing is being invoked. When I console logged the found variable I was able to get my result.

find() will return the first element of the array

Array.prototype.findIndex()

This method returns the index of the first element in the array that satisfies the testing case/conditional. Otherwise, it will return -1 — indicating that no element passed the test.

findIndex() returned the first index of the element that met the condition which is index of 3

Array.prototype.forEach()

This method will execute each item in the element and return all the elements from the array.

Array.prototype.includes()

This method determines whether the array contains a value we are checking for,it will return true or false as appropriate.

includes() returned true because “b” is included in the letters array

Array.prototype.map()

This method returns a new array containing the results of the calling function on every element of the original array. *THIS METHOD RETURNS A NEW ARRAY, you may see that this method is similar to the forEach() method but the differnce is that map returns a new array.

map() will return a new array of new elements ran by initial function

Conclusion:

Array methods in Javascript help us perform functions that could have been much more complicated otherwise. If you would like to learn more about more methods that are not covered in this blog check out this MDN site.

Happy Studying!

--

--