1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| let snacks = ['새우깡', '프링글스', '감자깡', '꿀꽈배기', '콘칩', '허니버터칩'] const result = snacks.filter(item => item.length > 3)
const aboveEighteen = (number) => { return number > 18 }
let numbers = [12, 5, 8, 33, 18, 22].filter(aboveEighteen) console.log(numbers)
const isEven = (number) => { return number % 2 === 0 }
let filteredNumbers = [1, 1, 3, 0, -10, 22, 900].filter(isEven) console.log(filteredNumbers)
let snacksTwo = ['새우깡', '프링글스', '감자깡', '꿀꽈배기', '콘칩', '허니버터칩', '매운 새우깡', '매운 감자깡'] const filterItems = (query) => { return snacksTwo.filter(snack => snack.indexOf(query) > -1) } console.log(filterItems('매운'))
let students = [ { id: 1, name: 'james', age: 30 }, { id: 2, name: 'tim', age: 40 }, { id: 3, name: 'jhon', age: 25 }, { id: 4, name: 'Anna', age: 39 }, { id: 5, name: 'bobby', age: 22 }, ]
const filterStudents = students.filter(e => e.age >= 30) console.log(filterStudents)
|