Overwrite an element at a specific position

I have a list and this list should remove the old element, but only for the element where the ID also matches. What is the best way to do this. The only thing I have so far is to delete the element. But is there no better option to just overwrite the item instead of deleting it?

The important thing is that the element should stay in the same place.

This is my list

const [days, setDays] = useState( 
[
  {
    id: 1,
    day: 'Monday'
  },
  {
    id: 2,
    day: 'Sunday'
  }

])

This are my parameters

const day = 'Friday' 
const id = 2

And the expected output

[
  {
    id: 1,
    day: 'Monday'
  },
  {
    id: 2,
    day: 'Friday'
  }

]

What I tried

const newDay = {
  id: id,
  day: day
};
setDays((days) => [
      ...days.map((day) =>
        day.id=== id ? newDay: day
      ),
    ]);

Answer

I solved your problem with the following code:

let result = days.map(item => (item.id === newday.id ? newday : item));

See my Stackblitz for full example: https://stackblitz.com/edit/web-platform-5r74df?file=script.js