1.0.0 • Published 7 years ago

merge-multiple-objects v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

merge-multiple-objects

Merges one or more objects into a given object.

Syntax

var mergeMultipleObj = require('merge-multiple-objects');

mergeMultipleObj(fromWhat, [toObject])

fromWhat : is either an object or an array of objects from which to merge
toObject : (optional) object to merge with

Installation

npm install merge-multiple-objects

https://npmjs.org/package/merge-multiple-objects
Source code available at: https://github.com/hakarapet/merge-multiple-objects

Usage

NodeJS

var mergeMultipleObj = require('merge-multiple-objects');
var objFrom = {
    foo: 'string_UPDATED',
    bar: {
        'a': 1,
        'b': 2
    }
}, objTo = {
    foo: 'string',
    bar: {
        'a': 0,
        'c': 3
    }
}
mergeMultipleObj(objFrom, objTo);

Result will be an object:

{
    bar: {
        'a': 1,
        'b': 2,
        'c': 3
    },
    foo: 'string_UPDATED'
}

Function also can merge array of objects into one object or into given object.

var array = [{'a': 1}, {'a': 2, 'b': 3}, {'c': 4}];
var toObj = {'a': 0};
mergeMultipleObj(array, toObj);

Result will be an object:

{
    'a': 2,
    'b': 3,
    'c': 4
}

Author

Hayk Karapetyan
hakarapet@gmail.com

License

MIT License
https://opensource.org/licenses/MIT