array method return boolean code example
Example 1: js find array return true false
['one', 'two'].some(item => item === 'one') // true
['one', 'two'].some(item => item === 'three') // false
Example 2: some js es6
const array = [1, 2, 3, 4, 5];
// checks whether an element is even
const even = (element) => element % 2 === 0;
console.log(array.some(even));
// expected output: true
Example 3: array method return boolean
let array = [1, 2, 3, 4, 5];
//Is any element even?
array.some(function(x) {
return x % 2 == 0;
}); // true
Example 4: js object some
let obj = {"num1":1, "num2":2, "num3":3, "num4":4, "num5":5};
var firstEven = null;
// Some returns a boolean value.
Object.values(obj).some((item) => {
// Loop breaks as soon as the condition has been met.
// Getting your value, can be used like:
if (item == 2) {
firstEven = item;
}
return item % 2 == 0;
}); // Results in true