Last active
May 30, 2018 09:32
-
-
Save arturparkhisenko/db604e314ea8ff8ba065 to your computer and use it in GitHub Desktop.
clone-js-object-array-etc
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
| const clone = data => { | |
| if (typeof data !== 'object' || data === null) { | |
| return data; | |
| } | |
| const copy = data instanceof Array ? data.constructor() : Object.create(Object.getPrototypeOf(data)); | |
| for (const [key, value] of Object.entries(data)) { | |
| copy[key] = clone(value); | |
| } | |
| return copy; | |
| }; | |
| export default clone; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment