General API

cloneObj()

Makes a deep copy of an object.

  • Accepts an argument as an object.
  • Returns a deep copy of the object, ensuring that references to DOM elements, functions, files, file lists, symbols, Date objects, regular expressions, and collections such as Set, Map, WeakSet, and WeakMap are preserved.
    If the argument is not an object, returns the passed value.
Example:
cloneObj({key: 'value'});
// {key: 'value'}

cloneObj({element: $('body')});
// {element: body}

cloneObj({elements: $('div ?')});
// {elements: [div, div, div]}

cloneObj({key: 'value', array: [1, 2, $('div')]});
// {key: 'value', array: [1, 2, div]}

cloneObj({key: {key2: 'value2'}});
// {key: {key2: 'value2'}}

cloneObj($('div'));
// {}

cloneObj($('div ?'));
// [div, div, div]

cloneObj('book');
// 'book'