
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
JavaScript Array some() function
The some() method of JavaScript is used to check if any of the elements in an array fulfills the condition.
The syntax is as follows −
array.some(function(currentVal, index, arr), val)
Above, the parameters under function(), include currentVal – value of the current element, index – array index, whereas val the array object the current element fits
Let us now implement the some() method in JavaScript −
Example
<!DOCTYPE html> <html> <body> <h2>Ranking Points</h2> <p>Is any point above 400...</p> <button onclick="display()">Result</button> <p id="demo"></p> <script> var pointsArr = [50, 100, 200, 300, 400, 500, 600]; function pointsFunc(points) { return points > 400; } function display() { document.getElementById("demo").innerHTML = pointsArr.some(pointsFunc); } </script> </body></html>
Output
Click the “Result” button −
Example
<!DOCTYPE html> <html> <body> <h2>Ranking Points</h2> <p>Is any point equal to 550...</p> <button onclick="display()">Result</button> <p id="demo"></p> <script> var pointsArr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1000]; function pointsFunc(points) { return points == 550; } function display() { document.getElementById("demo").innerHTML = pointsArr.some(pointsFunc); } </script> </body></html>
Output
Click the “Result” button −
- Related Articles
- Array some() function in JavaScript
- JavaScript Array find() function
- JavaScript Array fill() function
- JavaScript Array findIndex() function
- Array findIndex() function in JavaScript
- Sorting Array with JavaScript reduce function - JavaScript
- Check if some elements of array are equal JavaScript
- divisibleBy() function over array in JavaScript
- Constructing 2-D array based on some constraints in JavaScript
- Currified function that multiples array elements in JavaScript
- Accumulating some value over using a callback function and initial value in JavaScript
- Sorting an array that contains the value of some weights using JavaScript
- Which algorithm does the JavaScript Array#sort() function use?
- Accessing an array returned by a function in JavaScript
- How to remove some items from array when there is repetition in JavaScript

Advertisements