I am working with a variable that contains an array of objects
let Obj1 =
[
{Id: 123, name: 'A'},
{Id: 124, name: 'B'},
{Id: 125, name: 'C'},
{Id: 126, name: 'D'},
{Id: 127, name: 'E'}
]
let Obj2 = {Id:126, name: 'D'}
Is there a way to dynamically move Obj2 within Obj1 to the 0th index using Javascript or TypeScript? Obj2 is received from the backend and Obj1 is data already present in the frontend. The desired end result should look like this:
[
{Id: 126, name: 'D'},
{Id: 123, name: 'A'},
{Id: 124, name: 'B'},
{Id: 125, name: 'C'},
{Id: 127, name: 'E'}
]