javascript - How to merge two object values by keys -


trying see if there javascript library functionality can merge values specific key of 2 json objects

var x ={ "student-marks":{'math':1,'physics':5} }; var y ={ "student-marks":{'chemistry':3,'history':2} }; 

using $.extend , $.merge giving below results

$.extend({},x,y)  leads  { "student-marks":{'chemistry':3,'history':2} }  $.merge(x,y) leads { "student-marks":{'math':1,'physics':2} } 

what looking ‍{ "student-marks":{'math':1,'physics':5, 'chemistry':3,'history':2} }‍

you want deep extend

$.extend(true, {}, x, y); 

see docs jquery.extend([deep], target, object1[, objectn])


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -