DEV Community

Discussion on: 👨🏻‍💻 UnderStand the Most Powerful 💪 Function of Javascript

Collapse
 
jpantunes profile image
JP Antunes

Another interesting use case for reduce is to create a lookup table from an object and a property / key.

let phoneBook = students.reduce( (acc, val) => (acc[val.mobileNo] = val, acc), {})

> phoneBook[989481]
{ name: 'Kushal',
  class: 'MCA',
  result: 'Pass',
  mobileNo: '989481' }