JS Built-ins
← Array199 / 226
ArrayArray.prototype.toSplicedintermediate

toSpliced Does Not Mutate

πŸ“– Usage Example
const original = [1, 2, 3]
const result = original.toSpliced(0, 1)
original  // β†’ [1, 2, 3]  (unchanged)
result    // β†’ [2, 3]

toSpliced() is the immutable version of splice() β€” it never changes the source array.

Array.prototype.toSpliced β€” Immutability

Unlike splice, toSpliced never modifies the original array. This makes it safe to use in scenarios where immutability matters.

Implement checkSplicedImmutable which calls toSpliced(0, 1) but returns the original array.

πŸ’‘ Hints (2)
  • β€’ toSpliced returns a new array β€” you can safely ignore that return value
  • β€’ The original array reference is always left intact