Skip to content

Instantly share code, notes, and snippets.

@toejough
Created May 16, 2015 00:06
Show Gist options
  • Save toejough/df94aee238586c283b6f to your computer and use it in GitHub Desktop.
Save toejough/df94aee238586c283b6f to your computer and use it in GitHub Desktop.
clone javascript object
// clone a basic object (no functions or recursion)
// also handles 'undefined' and 'null'
function clone_obj(obj) {
if (obj === undefined || obj === null) {
return obj;
}
return JSON.parse(JSON.stringify(obj));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment