Last active
November 9, 2023 14:53
-
-
Save netstart/c8464f3987d22d5808d87020b5f3ef8f to your computer and use it in GitHub Desktop.
Example: How to clone Map with Array value in TypeScript
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
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