Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two objects -

a = {0:"hai",1:"hello"}
b = {0:"what",1:"you"}

I want to get a resulting object on merge of the following format

c = {0:"hai",1:"hello",2:"what",3:"you"}

I tried different merge techniques, but fail to achieve this. What are the optimal ways of achieving the above?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
323 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here's a solution that essentially converts the objects to arrays then merges them together using Array.prototype.concat:

Object.assign([], {0:"hai",1:"hello"}).concat(Object.assign([], {0:"what",1:"you"}))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...