DEV Community

Discussion on: 5 useful javascript tricks for begginers.

Collapse
 
coderslang profile image
Coderslang: Become a Software Engineer

That's a good one, although it might be useful to first filter out nulls and undefineds from the array:

const mostLengthy = someArray
    .filter(item => item)
    .reduce((acc, i) => i.length > acc.length ? i : acc);
Enter fullscreen mode Exit fullscreen mode

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