Using Array.prototype.some method

Did you ever got in a situation where you need to find that any one of an item in a collection satisfies the condition. if yes then you want to go ahead and do some stuff. Let’s look at this from code perspective

And the probable solution any developer would try should look like below

A better approach would be to use ‘some method’ from Array.prototype

If you can observe, some method takes a callback and returns a boolean value true/false. It returns true if any element in an array satisfies the condition passed as callback.

You can find more about this method in the below link


Leave a Reply

Your email address will not be published. Required fields are marked *