VOOZH about

URL: https://www.geeksforgeeks.org/typescript/typescript-array-some-method/

⇱ TypeScript Array some() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

TypeScript Array some() Method

Last Updated : 12 Jul, 2024

The Array.some() method in TypeScript is used to check if at least one element in the array passes the test implemented by the provided function.
Syntax:

array.some(callback[, thisObject])

Parameter: This method accepts two parameters as mentioned above and described below:

  • callback: This parameter is the Function to test for each element.
  • thisObject: This is the Object to use as this parameter when executing callback.

Return Value: This method returns true if some element in this array satisfies the provided testing function. 

The below example illustrates the  Array  some() method in TypeScriptJS:

Example 1: Checking for Positive Numbers

In this example, the some() method checks if there is at least one positive number in the array.

Output:

true

Example 2: Checking for String Length

In this example, the some() method checks if there is at least one string with a length greater than 5.

Output:

true
Comment
Article Tags:
Article Tags:

Explore