Looking to enhance an existing array of objects by adding a new object:
const oldArray = [{ name: 'First', value: 'one' }, { name: 'Second', value: 'two' }, { name: 'Third', value: 'three' }]
const newArray = [...oldArray, { name: 'Fourth', value: 'four' }]
The goal is to arrange newArray
so that the Fourth object is placed as the 3rd item (index 2) in oldArray
. Is there a way to configure newArray
so that the new object is inserted as the 3rd item in the ...oldArray
spread operator, without needing to rewrite all of the items in oldArray
in newArray
?