https://github.com/palashmon/clone-array-objects
Tiny module to clone an array of objects
https://github.com/palashmon/clone-array-objects
array array-item array-of-objects clone objects tests
Last synced: 6 months ago
JSON representation
Tiny module to clone an array of objects
- Host: GitHub
- URL: https://github.com/palashmon/clone-array-objects
- Owner: palashmon
- License: mit
- Created: 2018-07-14T05:20:05.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-10-30T22:19:06.000Z (about 1 year ago)
- Last Synced: 2024-11-12T21:44:12.832Z (about 1 year ago)
- Topics: array, array-item, array-of-objects, clone, objects, tests
- Language: JavaScript
- Homepage:
- Size: 81.1 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# clone-array-objects 
> 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
```js
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](https://github.com/palashmon)