//.some method accepts a callback function as an argument. If this
// function returns true for at least one element, the whole method
// returns true; otherwise it returns false.
const cities = [
"Orlando",
"Dubai",
"Denver",
"Edinburgh",
"Accra",
"Chennai",
"New York",
"Los Angeles",
];
const findLargeCity = (element) => {
return element === "New York" || element === "Los Angeles";
};
console.log(cities.some(findLargeCity));
// Expected output is true
// Use method "some" to loop through array elements and see if there are any matching ones
const array = [{ name: 'Dharmesh', gender: 'male' }, { name: 'Priti', gender: 'female' }];
const hasFemaleContender = array.some(({ gender }) => gender === 'female');
console.log(hasFemaleContender);
// an array
const array = [ 1, 2, 3, 4, 5 ];
// check if any of the elements are less than three (the first two are)
array.some(function(element) {
return element < 3;
}); // -> true
// ES6 equivalents
array.some((element) => {
return element < 3
}); // -> true
array.some((element) => element < 3); // -> true
It just checks the array,
for the condition you gave,
if atleast one element in the array passes the condition
then it returns true
else it returns false
movies.some(movie => movie.year > 2015)
// Say true if in movie.year only one (or more) items are greater than 2015
// Say false if no items have the requirement (like and operator)
<script>
// JavaScript code for some() function
function isodd(element, index, array) {
return (element % 2 == 1);
}
function geeks() {
var arr = [ 6, 1, 8, 32, 35 ];
// check for odd number
var value = arr.some(isodd);
console.log(value);
}
geeks();
</script>
var nums = [1, 2, 3, 4, 5, 6, 7];
function even(ele)
{
return ele%2 == 0;
}
console.log(nums.some(even))
/*consol.log will show true because at least one of the elements is even*/