Array Methods! Pt.3 (some, every)
A continuation from my previous blog post, we’ve made it to the third one! My thought process of breaking my blogs up was for people to take a quick read or refresher. I believe that is the best way to learn something thats either new or something you’ve once learned before, rather than going through a long tedious blog of mine! All jokes aside I cut these arrays into certain blogs for easier access as well.
Something that I haven’t used often at all is the some method. The some method tests at the very least one element in the array that passes the test implemented by the provided function. It returns true if in the array, it finds an element for which the provided function returns true, if false, the method will not modify the array. This was defined by MDN Web Docs, my interpretation of the some method is that the some has to figure out an element and then give a result as a boolean if true. If it returns false, then the array would not be modified. Complicated way to describe it, but ill show an example now:
Now for the every method, this is also another one I haven’t used much just yet. The every method is defined by MDN Web Docs as a method that tests wether all elements in the array pass the test implemented by the provided function. It returns a Boolean value. Somewhat self explanatory, but what I take from it, is that the method tests the function and will return a boolean being true or false depending on the outcome of the result.
Presenting you two of the least used in my own code was somewhat of a challenge for me to explain. I do hope you found it helpful and start using it in your everyday code! I will be trying to do the same! Always remember practice makes somewhat perfect and that everyday is a new day to learn something new! Thank you for taking the time to read this short blog!