1. shallow-copy
make a shallow copy of an object or array
shallow-copy
Package: shallow-copy
Created by: substack
Last modified: Tue, 08 Nov 2022 10:40:52 GMT
Version: 0.0.1
License: MIT
Downloads: 5,469,690
Repository: https://github.com/substack/shallow-copy

Install

npm install shallow-copy
yarn add shallow-copy

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

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code