Skip to content

Instantly share code, notes, and snippets.

@VinayakBagaria
Created September 15, 2019 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VinayakBagaria/5c2ebe08994e1620238b67c0f43b5672 to your computer and use it in GitHub Desktop.
Save VinayakBagaria/5c2ebe08994e1620238b67c0f43b5672 to your computer and use it in GitHub Desktop.
Recursive clone an array
function recursiveClone(val) {
return Array.isArray(val) ? Array.from(val, recursiveClone) : val;
}
const numbers = [[0, 1, 2], ['one', 'two', 'three']];
const numbersClone = recursiveClone(numbers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment