The with() method of an array returns a new array with the element at the given index replaced with the given element. It does not change the original array, it copies.

    
    const numbers = [1, 2, 3, 4, 5];

    const numbersWith = numbers.with(2, 6);

    console.log(numbersWith);
    // [1, 2, 6, 4, 5]

    console.log(numbers);
    // [1, 2, 3, 4, 5]