Check Any Value in Array Satisfy Condition | JavaScript


How to Check Any Value in Array Satisfy Condition Using JavaScript ?

To check if any value in JavaScript array satisfies the condition you can use Array.prototype.some() method. It returns true if any item in array satisfies the condition else returns false.

let data = [1,2,3,4,5,7];
let val = data.some(item => item > 6);
if(val){
	console.log('Numbers found greater than 6 ');
} else{
	console.log('No Numbers greater than 6 ');
}
// - "Numbers found greater than 6 "