Make a shallow clone of an object, array or primitive.
Install with npm:
$ npm install --save shallow-clone
var clone = require('shallow-clone');
The array itself is cloned, but not the elements of the array. So any objects in the array will still not be cloned (e.g. they will be the same object as in the orginal array).
var arr = [{ 'a': 0 }, { 'b': 1 }] var foo = clone(arr); // foo => [{ 'a': 0 }, { 'b': 1 }] // array is cloned assert.equal(actual === expected, false); // array elements are not assert.deepEqual(actual[0], expected[0]); // true
clone(0) //=> 0 clone('foo') //=> 'foo'
clone(/foo/g) //=> /foo/g
clone({a: 1, b: 2, c: 3 }) //=> {a: 1, b: 2, c: 3 }
Object
constructor. | homepagePull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Commits | Contributor |
---|---|
2 | doowb |
2 | jonschlinkert |
(This project‘s readme.md is generated by verb, please don’t edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on July 16, 2017.