JavaScript Array some() Method

You are Here:

JavaScript Array some() Method

The some() method returns a Boolean value by testing whether at least one element in the array passes the test implemented by the provided function.

Note: This method does not alter the original array.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Check atleast one number is less than 2<p> <script> var myNumber = [30, 35, 40, 1, 45, 50, 55]; function checkValue(num) { return num < 2; } document.write(myNumber.some(checkValue)); </script> </body> </html>

Syntax

Array.some(function(value, index, arr), thisArg); //or Array.some(functionName);

Parameter Values

ValueTypeExplanation
function(value, index, arr)RequiredFunction to test for each element in an array.
Value - Specifies a value or element in an array.
index - Specifies the index of a value or element in an array.
arr - Specifies the whole array.
thisArgOptionalSpecifies a value against which each element in an array is tested.

Return Values

ValueExplanation
trueIf at least one element in the array passes the test implemented by the provided function.
falseIf no elements in the array pass the test implemented by the provided function.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Check atleast one number is less than 2<p> <script> var myNumber = [30, 35, 40, 1, 45, 50, 55]; function checkValue(num, index, arr) { return num < this; } document.write(myNumber.some(checkValue, 2)); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author