I'm attempting to combine my two array, but move only the object.
I have an array called parentArr that I am attempting to combine with growthArr. When using the .push() method it is returning parentArr as an array inside of growthArr. I am attempting to combine the objects from parentArr and not have it nested inside of an array.
Here is an example of what is happening:
let growthArr = [
{
name: 'online stores',
parent: 'high'
}, {
name: 'retail stores',
parent: 'low'
}, {
name: 'walk in',
parent: 'high'
}
]
let parentArr = [
{
id: 'low',
color: '#fafafa'
}, {
id: 'med-low',
color: '#B62721'
}, {
id: 'med',
color: '#FF5733'
}, {
id: 'med-high',
color: '#FF33FC'
}, {
id: 'high',
color: '#33FF64'
}
]
growthArr.push(parentArr)
console.log(growthArr)
To work around this, I've tried doing growthArr.push.apply(parentArr) but by doing this my parentArr does not show at all.
Here is my expected outcome, an array with both the objects in growthArr and parentArr
[
{
"name": "online stores",
"parent": "high"
},
{
"name": "retail stores",
"parent": "low"
},
{
"name": "walk in",
"parent": "high"
},
{
"id": "low",
"color": "#fafafa"
},
{
"id": "med-low",
"color": "#B62721"
},
{
"id": "med",
"color": "#FF5733"
},
{
"id": "med-high",
"color": "#FF33FC"
},
{
"id": "high",
"color": "#33FF64"
}
]