33
Check if at least one Array item passes a condition
2021-03-10 - JavaScript
1// JS Tip of the Day
2// Check if at least one Array item passes a condition
3
4const heroes = [
5 { name: "Batman", superPower: "money" },
6 { name: "Superman", superPower: "flight" },
7 { name: "Wonder Woman", superPower: "superior strength" }
8];
9
10const haveMoney = heroes.some(hero => hero.superPower === 'money');
11console.log(haveMoney); // true
#JStipoftheday