Collect.js some() Method
Last Updated :
09 Dec, 2020
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 parameter.
Return Value: This method checks whether the given collection contains a given item or not and returns the corresponding boolean value.
Below example illustrate the some() method in collect.js:
Example 1:
Javascript
const collect = require( 'collect.js' );
const collection = collect([ 'Geeks' ,
'GFG' , 'GeeksforGeeks' , 'Welcome' ]);
const some_val = collection.some( 'GFG' );
console.log(some_val);
|
Output:
true
Example 2:
Javascript
const collect = require( 'collect.js' );
let obj = [
{
name: 'Rahul' ,
marks: 88
},
{
name: 'Aditya' ,
marks: 78
},
{
name: 'Abhishek' ,
marks: 87
}
];
const collection = collect(obj);
const some_val1 = collection.some(
element => element.name == 'Aditya' );
console.log(some_val1);
const some_val2 = collection.some(
element => element.name == 'Shyam' );
console.log(some_val2);
|
Output:
true
false
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...