29.
What is the output of the following code snippet?
const arr = [1, 2, 3, 4, 5];
const slicedArr = arr.slice(1, 3);
console.log(slicedArr);
[1, 2, 3]
[3, 4]
[1, 2]
[2, 3]
Correct: D
The slice() method returns a shallow copy of a portion of an array into a new array object. In this case, it starts slicing from the index 1 and stops at the index 3 (exclusive). So, the elements at index 1 and 2 ('2' and '3') are sliced and returned as the output.