JavaScript Array Methods

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”

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

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

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

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

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!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store