23.
What will be the output of the following code?
const arr = [1, 2, 3, 4, 5];
const slicedArr = arr.slice(1, 3);
console.log(slicedArr);
[3, 4]
[2, 3, 4]
[1, 2]
[2, 3]
Correct: D
The slice() method returns a new array containing the elements from the original array based on the specified start and end index. In this code, arr.slice(1, 3) starts at index 1 (value 2) and ends at index 3 (value 4), but does not include the element at the end index. Therefore, the slicedArr will contain [2, 3]. When logged to the console, it will output [2, 3].