Make a shallow clone of an object, array or primitive.
Install with npm
sh
$ npm i shallow-clone --save
js
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).
```js 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 ```
```js clone(0) //=> 0
clone('foo') //=> 'foo' ```
js
clone(/foo/g)
//=> /foo/g
js
clone({a: 1, b: 2, c: 3 })
//=> {a: 1, b: 2, c: 3 }
Object
constructor.Install dev dependencies:
sh
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on August 10, 2015.