Created
November 16, 2017 15:04
-
-
Save nonlogos/ac11b4b5508fa8a46a37b97abbde1411 to your computer and use it in GitHub Desktop.
deep copy for objects and arrays
This file contains hidden or 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 copy(object) { | |
| var output, value, key; | |
| output = Array.isArray(object) ? [] : {}; | |
| for (key in object) { | |
| value = object[key]; | |
| output[key] = (typeof value === 'object') ? copy(value) : value; | |
| } | |
| return output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment