Immutable Array Element Modification in JavaScript

Let's now learn how to perform immutable modification of elements in an array. For example, let's say we have some array:

javascriptlet arr = [1, 2, 3, 4, 5];

Let the index for modification be stored in variable ind:

javascriptlet ind = 3;

Let's modify the element at the given index. According to our approach, we should make a copy of the array and modify the element in the copy. Let's do this:

javascriptlet copy = Object.assign([], arr);
copy[ind] = '!';
let res = copy;

Let's use the second approach:

javascriptlet res = [
  ...arr.slice(0, ind),
  '!',
  ...arr.slice(ind + 1)
];
Задание 1

Create a button that, when clicked, will modify an array element. Let the index of the element to be modified be stored in a variable.