Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Flatten an array of arrays or map of arrays in Typescript single liner
/**
* Flatten a map of arrays or array of arrays to a single array
* @param t
*/
export function flatten<T>(t: Array<Array<T>> | { [p: string]: Array<T> }): Array<T> {
return Object.values(t).reduce((mem, val) => [...mem, ...val], [])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.