Working with Javascript Array some() method with examples for Beginners

In Javascript some() method calls the callback function on each item of the array and checks it against the condition and if the condition returns true it returns a boolean value true else returns false.

Syntax

array.some(callback_function, extra_arguments);
  • callback_function: Represents the function to be called on each item.
  • extra_arguments: Represents additional arguments to be passed to a callback function.

some() the method does not modify or change the existing array.

Table of Contents

Example

Variable arr is an array that consists a list of numbers and the callback function tests the condition against the number and returns the boolean value.

let arr = [3, 2, 9, 7];
let result = arr.some(function(num){
    return (num%2==0);
});

console.log(result);

//Console Output
true

The outcome of the above function returns true and the callback function stops when the condition of any number returns true and it further does not iterate over the array.

Conclusion

We have reached the Conclusion of our post Working with Javascript Array some() method with examples for Beginners. Comment if you have any doubts and if you like then help us grow by sharing this post.

Related Posts

Summary
Review Date
Reviewed Item
Working with Javascript Array some() method with examples for Beginners
Author Rating
51star
1star1star1star1star
Software Name
Javascript Programming
Software Name
Windows Os, Mac Os, Ubuntu Os
Software Category
Web Development