Created
September 15, 2019 22:52
-
-
Save VinayakBagaria/5c2ebe08994e1620238b67c0f43b5672 to your computer and use it in GitHub Desktop.
Recursive clone an array
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
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