Skip to content

Instantly share code, notes, and snippets.

@arifmahmudrana
Created January 8, 2020 05:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arifmahmudrana/993f01c3b78340e596fb5df286d7d05b to your computer and use it in GitHub Desktop.
Save arifmahmudrana/993f01c3b78340e596fb5df286d7d05b to your computer and use it in GitHub Desktop.
example of javascript array flat map alternative for typescript
// 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