jquery - How to merge two JavaScript Object litterals -
if have objects data1 , data2, how can make data3?
i send data3 parameter later in ajax request calling mvc server controller. (just saying can't have data3 array think).
var data1 = { managementpointid: 1, businessunitid: 2 }; var data2 = { computerpackageid: 3 }; var data3 = { managementpointid: 1, businessunitid: 2, computerpackageid: 3 };
use $.extend
method:
var data1 = { managementpointid: 1, businessunitid: 2 }; var data2 = { computerpackageid: 3 }; var data3 = $.extend({}, data1, data2); document.write('<pre>' + json.stringify(data3, null, 4) + '</pre>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Comments
Post a Comment