Currently, I am working on creating a new array from an existing one. The structure of my current array is outlined below. How can I ensure that adding a new object results in a new array starting from that point?
myArray: [{
animal: 'cat',
food: 'cupcake'
},
{
animal: 'dog',
food: 'pizza'
},
{
animal: 'lion',
food: 'apple'
},
{
animal: 'elephant',
food: 'spinach'
},
]
If I were to add a new Object like
{ animal: 'rhino', food: 'banana'}
, the result would be a new Array structured as:
newArray: [
{ animal: 'rhino', food: 'banana' }
]
Adding a new object to the original array should reflect in the new Array as well. I hope this explanation suffices.