some() / every()
01 Feb 2023 -
Less than 1 minute read
every()
-
λ°°μ΄μ λͺ¨λ μμκ° μ£Όμ΄μ§ 쑰건μ ν΄λΉνλμ§ νμΈ
-
λͺ¨λ ν΄λΉλλ©΄ true, κ·Έλ μ§ μμΌλ©΄ false 리ν΄
-
ex)
var array = ['10', '20', '30']; function num(element) { var num = (element % 10 == 0); return num; }; var rslt = array.every(num); console.log(rslt); // true
some()
-
λ°°μ΄ μ€ νλμ μμλΌλ μ£Όμ΄μ§ 쑰건μ ν΄λΉνλ©΄ true, κ·Έλ μ§ μμΌλ©΄ false 리ν΄
-
ex)
var array = ['10', '25', '30']; function num(element) { var num = (element % 10 == 0); return num; }; var rslt = array.some(num); console.log(rslt); // true
var array = ['bonjour', 'baguette', 'croissant']; function findO(element) { var o = element.includes("o"); return o; }; var rslt = array.every(findO); console.log(rslt); var rslt = array.some(findO); console.log(rslt); // false // true