some method to check an array in JavaScript
The following method some checks the
array elements and returns true if
the callback returned true for at
least one element, otherwise the method
returns false .
Let's check, for example, that there is at least one even number in the array:
let arr = [2, 4, 6, 8];
let result = arr.some(function(elem) {
return elem % 2 == 0;
});
console.log(result);
Let's simplify:
let arr = [2, 4, 6, 8];
let result = arr.some(elem => elem % 2 == 0);
console.log(result);
Given an array of numbers. Check that the array contains at least one number greater than zero.
Given an array of numbers. Check that
for at least one element the product
of its value and index number is
greater than 30.