On this simple trick I'll show how to remove an element from the array and add another one at the same index.
const people = ['John', 'Robert', 'Sylvia'];
const robertIndex = 1;
const slicedPeople = [...people.slice(0, robertIndex), 'Joe', ...people.slice(robertIndex+1, people.length)];
console.log(slicedPeople); // => output: ["John", "Joe", "Sylvia"];
What did you think of this tip? Feel free to comment.
so this doesn't mutate the people array but creates a new one, slicedpeople, with elements from people right?