How can the following operation be done without mutating the array:
let array = [\'item1\']; console.log(array); // [\'item1\'] array[2] = \'item2\'; // array is
function replaceAt(array, index, value) { const ret = array.slice(0); ret[index] = value; return ret; }
See the JSPerf (thanks to @Bless)
Related posts: