Socket
Socket
Sign inDemoInstall

shallow-copy

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    shallow-copy

make a shallow copy of an object or array


Version published
Weekly downloads
1.3M
increased by5.4%
Maintainers
1
Install size
5.71 kB
Created
Weekly downloads
 

Readme

Source

shallow-copy

make a shallow copy of an object or array

testling badge

build status

example

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;
dup.c.push(7);

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);

methods

var copy = require('shallow-copy')

copy(obj)

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.

install

With npm do:

npm install shallow-copy

license

MIT

Keywords

FAQs

Last updated on 25 Jul 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc