Last active
January 23, 2022 14:47
-
-
Save unostar/3c38c9cfaf406b0119f45f73fddfaf1d to your computer and use it in GitHub Desktop.
Filter out multi-dimensional arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.time("filter"); | |
let cat = ([].concat.apply([], this.transits.map(item => item.categories))).filter((value, index, self) => self.indexOf(value) === index); | |
console.timeEnd("filter"); | |
console.time("set"); | |
let cat2 = [...new Set([].concat.apply([], this.transits.map(item => item.categories)))]; | |
console.timeEnd("set"); | |
console.time("flat") | |
let cat3 = [...new Set(this.transits.map(item => item.categories).flat())]; | |
console.timeEnd("flat") | |
console.log(cat, cat2, cat3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment