JS Coding Questions Logo
JS Coding Questions
#344💼 Interview💻 Code

What is the purpose of some method in arrays

Advertisement

728x90

The some() method is used to test whether at least one element in the array passes the test implemented by the provided function. The method returns a boolean value. Let's take an example to test for any odd elements,

javascript
1var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
2
3var odd = (element) => element % 2 !== 0;
4
5console.log(array.some(odd)); // true (the odd element exists)

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 1

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
344of476