Array Methods! Pt. 2 (find, forEach)

Continuing from my previous blog post, if you haven’t checked it out yet heres a link! Small refresher of what is an array is; an array is a special variable that can hold more than one value at a time. With arrays being common, theres methods that you can use to help make your project more easier to create or just have an easier time accessing certain data within arrays.

The find method is a very popular one, for its function… finding something! I have used the find method multiple times especially when I have a UX where a user wants to search something then can use the search bar and in the background I have .find searching for that specific item!

find method

From the example above you can see the find method be rather self explanatory. When creating a const, we named it foundSneaker and had it set to a find method looking through an array of sneakers. We then return sneaker with a value of name that equals to the string of “Jordan 1” which should return the Jordan 1 from the array!

forEach method

The forEach is a loop that prints out whatever array its given. In this example we used the sneakers array once again and used the forEach method on it. Taking in a sneaker argument when then print out the array using console.log with the sneaker argument at the key of price. Behold! it goes through every single array printing out the price!

With these two example I truly hope that you’ve found them helpful and start using these methods more often for your array! At the very least I hope it solidifies your skillset or refreshes your time with methods! Thank you for reading and keep coding on!