Finding mistakes in code with arrays in JavaScript
In the following tasks, some programmer has written code and may have made mistakes in it. You should check if the code performs what is described. If the code doesn't work correctly, you have to correct the errors.
Задание 1
The code should output the last element of the array:
javascriptlet arr = [1, 2, 3, 4, 5];
console.log(arr[arr.length]);
Задание 2
The code should find the sum of the array elements:
javascriptlet arr = [1, 2, 3, 4, 5];
console.log(arr[1] + arr[2] + arr[3] + arr[4] + arr[5]);
Задание 3
The code should output the length of the array:
javascriptlet arr = {1, 2, 3, 4, 5};
console.log(arr.length]);
Задание 4
The code should output the length of the array:
javascriptlet arr = [1, 2, 3, 4, 5];
console.log(arr.lenght);