https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
filter()
๋ฉ์๋๋ ์ฃผ์ด์ง ํจ์์ ํ
์คํธ๋ฅผ ํต๊ณผํ๋ ๋ชจ๋ ์์๋ฅผ ๋ชจ์ ์๋ก์ด ๋ฐฐ์ด๋ก ๋ฐํํ๋ค.
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]
filter()
๋ ๋ฐฐ์ด ๋ด ๊ฐ ์์์ ๋ํด ํ ๋ฒ ์ ๊ณต๋ callback ํจ์๋ฅผ ํธ์ถํด, callback์ด true๋ก ๊ฐ์ ํ๋ ๊ฐ์ ๋ฐํํ๋ ๋ชจ๋ ๊ฐ์ด ์๋ ์๋ก์ด ๋ฐฐ์ด์ ์์ฑํ๋ค.
function isBigEnough(value) {
return value >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// filtered ๋ [12, 130, 44]