JavaScript Array Methods
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.
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.
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.
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.
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.
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!