Skip to content

Instantly share code, notes, and snippets.

@dreampiggy dreampiggy/Clone.js
Last active Jun 14, 2016

What would you like to do?
Clone object in JavaScript
'use strict';
function clone(obj) {
if (obj == null || typeof obj != "Object") {
return obj;
let copy = obj.constructor();
for (let attr in obj) {
if (obj.hasOwnProperty(attr)) {
copy[attr] = obj[attr];
return copy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.