最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Javascript Object - prepend object to existing object - Stack Overflow

matteradmin7PV0评论

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?

Post a comment

comment list (0)

  1. No comments so far