Skip to content

Latest commit

 

History

History
31 lines (22 loc) · 974 Bytes

README.md

File metadata and controls

31 lines (22 loc) · 974 Bytes

JS Deep Merge

MIT license Build Status

Object.deepMerge(target, source)
Array.deepMerge(target, source)

A tiny supportive script that enables deep JavaScript Object and Array merging.

Object

The script performs a complete deep merge and merges arrays with the Array merging script.

var object1 = { key1: value1 };
var object2 = { key2: value2 };
Object.deepMerge(object1, object2); // { key1: value1, key2: value2 }

Array

The script handles Arrays as Associative Arrays so the index is taken as the index and therefore replaced if the array to merge has a same index.

var array1 = [ 'key1', 'key2' ];
var array2 = [ 'key3' ];
Array.deepMerge(array1, array2); // [ 'key3', 'key2' ]