clone-array-objects

1.4.0 • Public • Published

clone-array-objects CI

Tiny module to clone an array of objects

Install

$ npm i clone-array-objects

Usage

This module helps us to get cloned array of objects

const cloneArrayObjects = require('clone-array-objects');
let users = [{ id: 1, username: 'bret' }, { id: 2, username: 'samantha' }];

// Clone this users array
let clonedUsers = cloneArrayObjects(users);
console.log(clonedUsers);
//=> [{ id: 1, username: 'bret' }, { id: 2, username: 'samantha' }];

// Let us modify one of the object key value in the actual users array
users[1].username = 'ava';

// So, actual users array has been updated now
console.log(users);
//=> [{ id: 1, username: 'bret' }, { id: 2, username: 'ava' }];

// But, the cloned users array is still the same
console.log(clonedUsers);
//=> [{ id: 1, username: 'bret' }, { id: 2, username: 'samantha' }];

API

cloneArrayObjects(arrayInput)

arrayInput

Type: Array
Default: []

Must be a JavaScript Array. This is main array of object that we will like to clone.

License

MIT © Palash Mondal

Package Sidebar

Install

npm i clone-array-objects

Weekly Downloads

292

Version

1.4.0

License

MIT

Unpacked Size

3.41 kB

Total Files

4

Last publish

Collaborators

  • palashmon