Open this example in the interactive library
Source code
const original = ["draft", "review"];
console.log(original.with(-1, "published"), original);
Sample output
[ 'draft', 'published' ] [ 'draft', 'review' ]

Open this example in the interactive library
const original = ["draft", "review"];
console.log(original.with(-1, "published"), original);
[ 'draft', 'published' ] [ 'draft', 'review' ]