The toSpliced() method of an array returns a new array with some elements removed, replaced or added at a given index. Unlike splice(), it does not affect the original array, it copies it.

    
    const months = ["Jan", "Mar", "Apr", "May"];

    // Insert at index 1, delete 0, add new elements(s)
    const months2 = months.toSpliced(1, 0, "Feb");
    console.log(months2);
    // ["Jan", "Feb", "Mar", "Apr", "May"]

    // Delete at index 2, delete 2
    const months3 = months2.toSpliced(2, 2);
    console.log(months3);
    // ["Jan", "Feb", "May"]

    // Replace at index 1, delete 1, add new element(s)
    const months4 = months3.toSpliced(1, 1, "Feb", "Mar");
    console.log(months4);
    // ["Jan", "Feb", "Mar", "May"]

    // the original array is not changed
    console.log(months);
    // ["Jan", "Mar", "Apr", "May"]