Skip to content

Instantly share code, notes, and snippets.

@bendc
Created October 25, 2016 08:07
Show Gist options
  • Save bendc/54f9f4985d848fb33d6838a61c908987 to your computer and use it in GitHub Desktop.
Save bendc/54f9f4985d848fb33d6838a61c908987 to your computer and use it in GitHub Desktop.
Deep clone a Map containing JSON-compatible data
const clone = map =>
new Map(JSON.parse(JSON.stringify([...map])));
@bendc
Copy link
Author

bendc commented Oct 25, 2016

Example:

const foo = new Map;
foo.set("array", []);

const bar = clone(foo);
foo.get("array").push(1);

console.log(bar.get("array")); // => []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment