Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
JavaScript Array sort() Method
Next article icon

JavaScript Array some() Method

Last Updated : 12 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The some() method checks if any array elements pass a test provided as a callback function, returning true if any do and false if none do. It does not execute the function for empty elements or alter the original array.

Syntax

arr.some(callback(element,index,array),thisArg);

Parameters

  • callback: This parameter holds the function to be called for each element of the array.
    • element: The parameter holds the value of the elements being processed currently.
    • index: This parameter is optional, it holds the index of the currentValue element in the array starting from 0.
    • array: This parameter is optional, it holds the complete array on which Array.every is called.
  • thisArg: This parameter is optional, it holds the context to be passed as this is to be used while executing the callback function. If the context is passed, it will be used like this for each invocation of the callback function, otherwise undefined is used as default.

Return value

Returns true if any of the array elements pass the test, otherwise false.

Example: In this example the Function checkAvailability checks if a value exists in an array using some(). Function func tests checkAvailability to see if 2 and 87 exist in the array.

JavaScript
function checkAvailability(arr, val) {     return arr.some(function (arrVal) {         return val === arrVal;     }); } function func() {     // Original function     let arr = [2, 5, 8, 1, 4];      // Checking for condition     console.log(checkAvailability(arr, 2));     console.log(checkAvailability(arr, 87)); } func(); 

Output
true false 

Example : In this example the Function isGreaterThan5 checks if any element in an array is greater than 5. Function func uses some() method to verify if any element in array satisfies condition.

JavaScript
function isGreaterThan5(element, index, array) {     return element > 5; } function func() {     // Original array     let array = [2, 5, 8, 1, 4];      // Checking for condition in array     let value = array.some(isGreaterThan5);      console.log(value); } func(); 

Output
true 

Example : In this example the Function isGreaterThan5 checks if any element in an array is greater than 5. Function func uses some() to verify if any element in array satisfies condition.

JavaScript
function isGreaterThan5(element, index, array) {     return element > 5; } function func() {     // Original array     let array = [-2, 5, 3, 1, 4];      // Checking for condition in the array     let value = array.some(isGreaterThan5);      console.log(value); } func(); 

Output
false 

We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari


Next Article
JavaScript Array sort() Method

H

HGaur
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • javascript-array
  • JavaScript-Methods

Similar Reads

  • JavaScript Array() Constructor
    The Array() constructor is used to create Array objects and the array constructor can be called with or without a new keyword, both can create a new Array. Syntax:new Array(Value1, Value2, ...);new Array(ArrayLength);Array(Value1, Value2, ...);Array(ArrayLength);Parameters: ValueN: An array initiali
    2 min read
  • JavaScript Array constructor Property
    The JavaScript Array constructor property is used to return the constructor function for an array object. It only returns the reference of the function and does not return the name of the function. In JavaScript arrays, it returns the function Array(){ [native code] }. Syntax: array.constructorRetur
    2 min read
  • JavaScript Array length
    JavaScript array length property is used to set or return the number of elements in an array. [GFGTABS] JavaScript let a = ["js", "html", "gfg"]; console.log(a.length); [/GFGTABS]Output3 Setting the Length of an ArrayThe length property can also be used to set the lengt
    2 min read
  • JavaScript Array from() Method
    The JavaScript Array from() method returns an Array object from any object with a length property or an iterable object. Syntax : Array.from(object, mapFunction, thisValue)Parameters:object: This Parameter is required to specify the object to convert to an array.mapFunction: This Parameter specifies
    3 min read
  • JavaScript Array isArray() Method
    The isArray() method in JavaScript is used to determine whether a given value is an array or not. This method returns true if the argument passed is an array else it returns false. Syntax:Array.isArray(obj);Parameters:obj: This parameter holds the object that will be tested.Return value:This functio
    3 min read
  • JavaScript Array of() Method
    The Javascript array.of() method is an inbuilt method in JavaScript that creates a new array instance with variables present as the argument of the method. Syntax:Array.of(element0, element1, ....)Parameters: Parameters present are element0, element1, .... which are basically an element for which th
    2 min read
  • Javascript Array at() Method
    The JavaScript Array at() method takes an integer value (index) as a parameter and returns the element of that index. It allows positive and negative integers. For the negative integer, it counts back from the last element in the array. Syntax: at(index);Parameter: This method accepts one parameter
    3 min read
  • JavaScript Array concat() Method
    The concat() method concatenates (joins) two or more arrays. It returns a new array, containing the joined arrays. This method is useful for combining arrays without modifying the originals. Syntax:let newArray1 = oldArray.concat()let newArray2 = oldArray.concat(value0)let newArray3 = oldArray.conca
    3 min read
  • JavaScript Array copyWithin() Method
    The Javascript Array.copyWithin() method considers an array first and then copies part of an array to the same array itself and returns it, without modifying its size but yet the modified data whatever user wishes to have in another's place i.e, copies array element of an array within the same array
    3 min read
  • JavaScript Array entries() Method
    The entries() method in JavaScript is used to create an iterator that returns key/value pairs for each index in the array. It allows iterating over arrays and accessing both the index and value of each element sequentially. Syntax:array.entries()Parameters:This method does not accept any parameters.
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences