I would like to merge an array with another array. The only catch is that each array is within an object.
Intuitively I tried {...arrObj, ...newArrObj} however this leads newArrObj overwriting items in the arrObj.
const array = ['an', 'array'];
const newArray = [, , 'new', 'ehrray'];
const obj = {
  key: { ...array
  }
};
const newObj = {
  key: { ...newArray
  }
};
const merged = { ...obj,
  ...newObj
};
console.log(merged);I would expect merged to be:
{
  "key": {
    "0": "an",
    "1": "array",
    "2": "new",
    "3": "ehrray"
  }
}
but receive
{
  "key": {
    "2": "new",
    "3": "ehrray"
  }
}
 
     
    