DEV Community

Discussion on: 5 useful javascript tricks for begginers.

Collapse
 
mdegoys profile image
Matthieu • Edited

You can also do this way I believe (sort by the length of the words in descending order, then pick the first one).

const mostLengthy = someArray.sort((x, y) => y.length - x.length)[0] 
Enter fullscreen mode Exit fullscreen mode

Maybe it's more understandable ? But I agree reduce is great :).

Some comments have been hidden by the post's author - find out more