Joining two arrays of objects in JavaScript [closed]

  javascript

EDIT: So the wonderful folks below who helped out pointed me in the right direction but I think it’s actually a problem with nextjs and apollo returning data? Here’s what the actual data looks like:

dataset1:  
Object { features: {…}, regions: {…}, ownerships: {…}, campgrounds: {…} }
​
campgrounds: Object { __typename: "RootQueryToCampgroundConnection", pageInfo: {…}, edges: (100) […] }
​
features: Object { __typename: "RootQueryToFeatureConnection", nodes: (38) […] }
​
ownerships: Object { __typename: "RootQueryToOwnershipConnection", nodes: (3) […] }
​
regions: Object { __typename: "RootQueryToRegionConnection", nodes: (7) […] }
​
<prototype>: Object { … }

and data set 2:

dataset2:  
Object { features: {…}, regions: {…}, ownerships: {…}, campgrounds: {…} }

I feel like there has to be a obvious answer to this, but all I get via a google search is how to merge objects, which is not waht I want. For example let’s say I have (pseudocode):

const cats = [{
name: "Pawl",
age: 2,
},
{
name: "Siam",
age: 6,
}
]

and I also have:

const dogs = [
{
name: "Ryu",
age: "1",
},
{
name: "Ken",
age: 5,
}
]


How would I go about getting this result from a new variable:

const animals = [{
name: "Pawl",
age: 2",
},
{
name: "Siam",
age: 6,
},
{
name: "Ryu",
age: "1",
},
{
name: "Ken",
age: 5,
}
]

Right now, if I try const animals = {…cats, …dogs} I just get dogs as the data, since it’s unioninzing (is that the word?) them.

Appreciate any help!

Source: Ask Javascript Questions

LEAVE A COMMENT