Skip to content
make shallow copies of objects and arrays
Latest commit 289e731 Jul 24, 2013 @substack fix keys -> obj typo
Failed to load latest commit information.
example examples into tests Jul 24, 2013
test examples into tests Jul 25, 2013
.travis.yml testling and travis Jul 24, 2013
LICENSE package.json etc Jul 24, 2013
index.js fix keys -> obj typo Jul 24, 2013
package.json fix keys -> obj typo Jul 25, 2013
readme.markdown testling and travis Jul 25, 2013



make a shallow copy of an object or array

testling badge

build status


you can copy objects shallowly:

var copy = require('shallow-copy');

var obj = { a: 3, b: 4, c: [5,6] };
var dup = copy(obj);
dup.b *= 111;

console.log('original: ', obj);
console.log('copy: ', dup);

and you can copy arrays shallowly:

var copy = require('shallow-copy');

var xs = [ 3, 4, 5, { f: 6, g: 7 } ];
var dup = copy(xs);
dup.unshift(1, 2);
dup[5].g += 100;

console.log('original: ', xs);
console.log('copy: ', dup);


var copy = require('shallow-copy')


Return a copy of the enumerable properties of the object obj without making copies of nested objects inside of obj.

If obj is an array, the result will be an array. If obj is an object, the result will be an object. If obj is not an object, its value is returned.


With npm do:

npm install shallow-copy



Something went wrong with that request. Please try again.