Let’s swap the first and second elements of the array.
- At the end of the program, add the variable
swap with value
- Then, write the value of the element with index
1 into the element of the array with index
- Log the array in the console below. Look, the first value is lost if we do not save it in a variable in advance.
- Then write the value of variable
swap into the element of the array with index
- And once again log the array in the console.