Created
January 8, 2020 05:27
-
-
Save arifmahmudrana/993f01c3b78340e596fb5df286d7d05b to your computer and use it in GitHub Desktop.
example of javascript array flat map alternative for typescript
This file contains hidden or 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
// example of array flat map alternative | |
const data = [ | |
{ | |
city: [ | |
{ | |
country: "Bhutan" | |
}, | |
{ | |
country: "Bhutan" | |
}, | |
{ | |
country: "Bhutan" | |
} | |
] | |
} | |
]; | |
console.log( | |
data | |
.map(({ city }) => city.map(({ country }) => country)) | |
.reduce((x, y) => x.concat(y), []) // [...x, ...y] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment