Skip to content

Instantly share code, notes, and snippets.

@netstart
Last active November 9, 2023 14:53
Show Gist options
  • Save netstart/c8464f3987d22d5808d87020b5f3ef8f to your computer and use it in GitHub Desktop.
Save netstart/c8464f3987d22d5808d87020b5f3ef8f to your computer and use it in GitHub Desktop.
Example: How to clone Map with Array value in TypeScript
clone(mapIn: Map<number, Array<Product>>): Map<number, Array<Product>> {
let mapCloned: Map<number, Array<Product>> = new Map<number, Array<Product>>();
mapIn.forEach((products: Array<Product>, key: number, mapObj: Map<number, Array<Product>>) => {
//products.slice(0) clone array
mapCloned.set(key, products.slice(0));
});
return mapCloned;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment