1['one', 'two'].some(item => item === 'one') // true
2['one', 'two'].some(item => item === 'three') // false
1// array.every(function(elemnt)) method takes in a function
2// which evaulates each elment
3// The every method is designed to check if all the elements
4// in an array meet a specific condition
5// This condition is defined within your function
6
7let numbers = [1, 2, 3, 42, 3, 2, 4, -1];
8
9let allPassed = numbers.every(function(element){
10 return element > 0;
11});
12
13// This method returns a Boolean value
14// allPassed is set to false because not all elements were greater than 0
15
16
1const array = [1, 2, 3, 4, 5];
2// checks whether an element is even
3const even = (element) => element % 2 === 0;
4console.log(array.some(even));
5// expected output: true
1let array = [1, 2, 3, 4, 5];
2
3//Is any element even?
4array.some(function(x) {
5 return x % 2 == 0;
6}); // true
1const fruits = ['apple', 'banana', 'mango', 'guava'];
2
3function checkAvailability(arr, val) {
4 return arr.some(function(arrVal) {
5 return val === arrVal;
6 });
7}
8
9checkAvailability(fruits, 'kela'); // false
10checkAvailability(fruits, 'banana'); // true
1let obj = {"num1":1, "num2":2, "num3":3, "num4":4, "num5":5};
2
3var firstEven = null;
4
5// Some returns a boolean value.
6Object.values(obj).some((item) => {
7 // Loop breaks as soon as the condition has been met.
8 // Getting your value, can be used like:
9 if (item == 2) {
10 firstEven = item;
11 }
12 return item % 2 == 0;
13}); // Results in true