DEV Community

Chau Lai Gia Thanh
Chau Lai Gia Thanh

Posted on

Javascript tổng hợp

ARRAY

Array filter

const people = [
  { name: 'Jon', age: 23 },
  { name: 'Daenerys', age: 23 },
  { name: 'Arya', age: 17 }
]

const children = people.filter(person => person.age < 18)
// Returns [ { name: 'Arya', age: 17} ]
Enter fullscreen mode Exit fullscreen mode

Array filter

const people = [
  { name: 'Jon', age: 23 },
  { name: 'Daenerys', age: 23 },
  { name: 'Arya', age: 17 }
]

const adult = people.find(person => person.age >= 18)
// Returns { name: 'Jon', age: 23 }
Enter fullscreen mode Exit fullscreen mode

Array forEach

const people = [
  { name: 'Jon', age: 23 },
  { name: 'Daenerys', age: 23 },
  { name: 'Arya', age: 17 }
]

people.forEach(person => sendNotification(person))
Enter fullscreen mode Exit fullscreen mode

Top comments (0)