clone source npm

_.clone(value)

Creates a shallow clone of value.

Note: This method is loosely based on the structured clone algorithm. The enumerable properties of arguments objects and objects created by constructors other than Object are cloned to plain Object objects. An empty object is returned for uncloneable values such as functions, DOM nodes, Maps, Sets, and WeakMaps.

Arguments

  1. value (*)

    The value to clone.

Returns (*)

Returns the cloned value.

Example

var users = [
  { 'user': 'barney' },
  { 'user': 'fred' }
];

var shallow = _.clone(users);
console.log(shallow[0] === users[0]);
// => true