Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Object - prepend object to existing object

I have this javascript objects.

<script language="javascript" type="text/javascript">
var jsObject1 = {'Mr.':'1','Mrs.':'2','Ms.':'3'} 
</script>

I want to add this javascript object to the beginning of the jsObject variable:

<script language="javascript" type="text/javascript">
var jsObject2 = {'Dr.':'4','Sr.':'5','Jr.':'6'} 
</script>

Is there a javascript function, or perhaps jquery method for doing that?

like image 291
coffeemonitor Avatar asked Oct 20 '22 23:10

coffeemonitor


1 Answers

There are various utility methods available to you that will do this, such as jQuery's extend() function. Or you could write your own function to achieve this as described here:

How can I merge properties of two JavaScript objects dynamically?

like image 180
ColinE Avatar answered Oct 24 '22 18:10

ColinE