I am trying to merge the objects recursively.
what I have
arrayOfObjects = [{a1:{aa:k1}},{a1:{ab:k2}},{a1:{ac:k3}},{a1:{aa:k4}},{a1:{ab:k5}}]; what I need is
{a1:{aa:k1,ab:k2,ac:k3,aa:k4,ab:k5}} I made a function
function merg(array){ value = {}; if(array.length>0){ $.each(array, function (i) { value = $.extend(true,{},value,array[i]); }); } return value; }; console.log(merg(arrayOfObjects)); what I get is
{a1:{aa:k1,ab:k2,ac:k3}} aa:k4,ab:k5 are missing(may due to same key value )
if the deep merge is false I get only one value
value = $.extend({},value,array[i]); {a1:{aa:k1}}
a1.aa. Which value do you expect to get, is it k1 or k4? How do you differ them?