JS Built-ins
← Array220 / 226
ArrayArray.prototype.withintermediate

Confirm New Array Reference

πŸ“– Usage Example
const arr = [10, 20, 30]
const result = arr.with(1, 200)
result !== arr  // β†’ true  (different reference)

with() returns a brand new array β€” the result and the source are distinct objects.

Array.prototype.with β€” New Reference

with() always returns a new array, even if the value is the same. The result is never the same reference as the original.

Implement withReturnsNew that returns true if arr.with(0, 99) !== arr.

πŸ’‘ Hints (2)
  • β€’ `with()` always allocates a new array object.
  • β€’ Use `!==` to compare object references.