Array.prototype.toSplicedintermediateconst arr = [1, 2, 4, 5]
arr.toSpliced(2, 0, 3) // β [1, 2, 3, 4, 5]
arr // β [1, 2, 4, 5] (unchanged)Use toSpliced() to insert elements at a position without modifying the original array.
Passing 0 as the delete count lets you insert elements without removing any.
Implement insertImmutable which returns a new array with val inserted at index.