array some
use of Array.some()
HTML
<script src="https://cdn.jsdelivr.net/gh/eu81273/jsfiddle-console/console.js"></script>
JavaScript
const userList = [
{ name: 'Alex', age: 51, country: 'USA' },
{ name: 'Varun', age: 26, country: 'India' },
{ name: 'Raman', age: 16, country: 'India' },
{ name: 'Max', age: 11, country: 'USA' },
{ name: 'Vishal', age: 32, country: 'India' }
];
/* Finding if there is any India User */
const indianUserExist = userList.some(user => {
return user.country === 'India';
});
/* Printing variable indianUserExist */
console.log('Is there any Indian User:-',indianUserExist);
/* Finding if there is any User whose age is greater than 18 */
const eighteenPlusUserExist = userList.some(user => {
return user.age > 18;
});
/* Printing variable eighteenPlusUserExist */
console.log('Is there any 18+ user:-',eighteenPlusUserExist);
/* Finding if there is any UAE User */
const uaeUserExist = userList.some(user => {
return user.country === 'UAE';
});
/* Printing variable uaeUserExist */
console.log('Is there any UAE User:-',uaeUserExist);