Array.prototype.spliceintermediateconst arr = ['a', 'b', 'c']
arr.splice(1, 1, 'X') // β ['b'] (removed)
arr // β ['a', 'X', 'c']Use splice() to replace one or more elements at a position with new values.
By passing 1 as deleteCount and a new value as the third argument, you can replace an element at any position in a single operation.
Challenge: Implement replaceAt(arr, index, val) that replaces the element at index with val and returns the mutated array.
replaceAt([1, 2, 3], 1, 99) // β [1, 99, 3]
replaceAt([10, 20, 30], 0, 5) // β [5, 20, 30]