Array.prototype.toSplicedintermediateconst arr = ['a', 'b', 'c']
arr.toSpliced(1, 1, 'X') // β ['a', 'X', 'c']
arr // β ['a', 'b', 'c'] (unchanged)Use toSpliced() to replace elements at a position, returning a new array.
Combining a delete count of 1 with a replacement value lets you replace an element at a given index without mutating the original.
Implement replaceImmutable which returns a new array with the element at index replaced by val.