Javascript Object - prepend object to existing object - Stack Overflow

admin2025-04-26  1

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?

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?

Share Improve this question asked Oct 1, 2013 at 4:56 coffeemonitorcoffeemonitor 13.2k35 gold badges105 silver badges153 bronze badges 2
  • 1 Possible duplicate : How can I merge properties of two JavaScript objects dynamically? – Pascalz Commented Oct 1, 2013 at 5:01
  • What does "beginning of the variable" mean? JavaScript objects are unordered. There is no beginning. – user2736012 Commented Oct 1, 2013 at 5:29
Add a ment  | 

1 Answer 1

Reset to default 3

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?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745604760a309515.html

最新回复(0)