How to Check Every Value in Array Satisfy Condition Using JavaScript ?
To check every value in JavaScript array you can use Array.prototype.every()
method. It returns true
if each item in array satisfies the condition else false
.
let data = [1,2,3,4,5];
let val = data.every(item => item < 6);
if(val){
console.log('Numbers less than 6 ');
} else{
console.log('Numbers greater than 6 ');
}
// "Numbers less than 6 "