some方法
● 我们先回顾一下includes方法
console.log(movements.includes(-130));
只要数组中存在-130这个值,就会返回true,否则就会返回flase
● 而some方法只要达成某一个条件就会返回true,否则就返回flase
const someMethod = movements.some(mov => mov > 0);
console.log(someMethod); //只要数组中有大于0的数字就返回true
● 我们现在利用some方法去实现应用程序中申请贷款的功能
btnLoan.addEventListener('click', function (e) {e.preventDefault();const amount = Number(inputLoanAmount.value);if (amount > 0 && currentAccount.movements.some(mov => mov >= amount * 0.1)) {currentAccount.movements.push(amount);updateUI(currentAccount);}inputLoanAmount.value = '';
});
every方法
every方法需要所有数组都满足条件才返回true,否则返回flase
console.log(movements.every(mov => mov > 0));