Problem: You want to copy a JavaScript array but use a different value for...


Problem: You want to copy a JavaScript array but use a different value for one index.

Solution: Array .with

Array .with copies the array instead of mutating it, and allows specifying a different value for a certain index.

Browser support:

View original on X