- script.js
JavaScript
var usersByDay = [4, 1, 2, 3];
console.log(usersByDay);
Result
Goalscompleted
Let’s swap the first and second elements of the array.
- At the end of the program, add a variable
swap
with valueusersByDay[0]
. - Then, write the value of the element with index
1
into the element of the array with index0
. - 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 index1
. - And once again log the array in the console.
Comments