A
I personally feel that in this case the improved code can be more readable and doesn't need any other libraries by using full es6 potential nodes .map(node => node.followers.map(user => user.email)) // get all emails in a format [['abc@abc.com', 'ijk@ijk.com'...], ['abc@abc.com', ...], ...] .reduce((emails, result) => [...emails, ...result], []) // flatMap like function, flat all the arrays into one .filter((email, i, self ) => self .indexOf(email) === i) // get all uniq items .filter(mail => mail) // remove undefined or null https://jsfiddle.net/ae1nof9p/
CommentArticleMar 16, 20171JavaScript Patterns โ Wrangling arrays like a boss, with Array#reduce ๐