An open API service indexing awesome lists of open source software.

https://github.com/writetome51/get-object-modified

Function merges one object into another and returns new, modified object
https://github.com/writetome51/get-object-modified

clone copy javascript modify object typescript

Last synced: 12 months ago
JSON representation

Function merges one object into another and returns new, modified object

Awesome Lists containing this project

README

          

# getObjectModified(
      object,
      changes: object
): object

Returns a new copy of `object` with `changes` merged into it.
Neither of the two arguments get modified. Prototype chain stays intact.

## Examples
```js
let obj = {prop1: 10, prop2: 20, prop3: 30};
let changes = {prop1: 100, prop2: 200, prop4: 1000};
getObjectModified(obj, changes);
// --> {prop1: 100, prop2: 200, prop3: 30, prop4: 1000}

obj = {prop1: 10, prop2: 20};
changes = {
prop1: 100,
prop3: function () {
return this.prop1 + this.prop2;
}
};
let newObj = getObjectModified(obj, changes);

console.log(newObj.prop3());
// console: '120'
```

## Installation

```bash
npm i @writetome51/get-object-modified
```

## Loading
```js
import {getObjectModified} from '@writetome51/get-object-modified';
```