Open In App

TypeScript Array some() Method

Last Updated : 03 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The Array.some() is an inbuilt TypeScript function which is used to check for some element in the array passes the test implemented by the provided function.
Syntax:

array.some(callback[, thisObject])

Parameter: This method accept two parameter as mentioned above and described below:

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

Return Value: This method returns true if some element in this array satisfies the provided testing function. 
Below example illustrate the  Array  some() method in TypeScriptJS:
Example 1: 

TypeScript




// check for positive number 
function ispositive(element, index, array)
   return element > 0;
 
// Driver code
var arr = [ 11, 89, 23, 7, 98 ]; 
  
// check for positive number 
var value = arr.some(ispositive); 
console.log( value );


Output: 

true

Example 2: 

TypeScript




// check for even number 
function iseven(element, index, array) 
{  
   return (element % 2 == 0);  
}   
// Driver code
var arr = [ 11, 89, 23, 7, 91 ]; 
  
// check for positive number 
var value = arr.some(iseven); 
console.log( value );


Output: 

 

false

 


Previous Article
Next Article

Similar Reads

What is the use of the Array.some() method in JavaScript ?
The Array.some() method in JavaScript is used to check if at least one element in an array satisfies a given condition. It returns true if at least one element in the array passes the test implemented by the provided function otherwise, it returns false. Example: Here, the condition in the some() method checks if there is at least one element great
1 min read
JavaScript Array some() Method
JavaScript arr.some() method checks whether at least one of the elements of the array satisfies the condition checked by the argument method. The some() method does not change the original array. Array some() Method Syntaxarr.some(callback(element,index,array),thisArg);Array some() Method Parameterscallback: This parameter holds the function to be
3 min read
JavaScript typedArray.some() Method
The typedArray.some() is an inbuilt function in JavaScript which is used to check whether some elements of the typedArray satisfy the test implemented by the given function. Syntax: typedarray.some(callback) Parameters: It takes the parameter callback function and this callback function takes three parameters that are specified below- Value: It tak
2 min read
Collect.js some() Method
The some() method is used to check whether the given collection contains a given item or not and returns the corresponding boolean value. Syntax: collect(array).some(key/value) Parameters: The collect() method takes one argument that is converted into the collection and then some() method is applied on it. The some() method holds the key/value as p
1 min read
Lodash _.some() Method
Lodash _.some() method is used to check if the predicate returns true for any element of the collection. Iteration is stopped once the predicate returns true. Syntax: _.some(collection, [predicate])Parameters:collection (Array|Object) parameter holds the collection to iterate over.predicate(Function) parameter holds the function invoked per iterati
2 min read
Some newly introduced array methods in JavaScript ES6
An array is used to store the elements of multiple data types in JavaScript altogether. Also, there are certain times when you have to manipulate the response received from the APIs as per the requirements on the webpages. Sometimes, the responses are objects and have to be converted to the arrays to perform the desired operations. These methods of
3 min read
TypeScript | Array unshift() Method
The Array.unshift() is an inbuilt TypeScript function that is used to add one or more elements to the beginning of an array and returns the new length of the array. Syntax: array.unshift( element1, ..., elementN ) Parameter: This method accepts n number of similar elements. element1, ..., elementN : This parameter is the elements to add to the fron
1 min read
TypeScript Array toString() Method
The Array.toString() is an inbuilt TypeScript function that is used to get a string representing the source code of the specified array and its elements. Syntax: array.toString() Parameter: This method does not accept any parameter. Return Value: This method returns the string representing the array. Below example illustrate the String toString() m
1 min read
TypeScript Array splice() Method
The Array.splice() is an inbuilt TypeScript function which is used to change the content of an array, adding new elements while removing old elements.Syntax: array.splice(index, howMany, [element1][, ..., elementN]); Parameter: This method accept three parameter as mentioned above and described below: index : This parameter is the index at which to
1 min read
TypeScript | Array sort() Method
The Array.sort() is an inbuilt TypeScript function which is used to sort the elements of an array. Syntax: array.sort( compareFunction ) Parameter: This method accept a single parameter as mentioned above and described below: compareFunction : This parameter is the function that defines the sort order Return Value: This method returns the sorted ar
1 min read