Question #27

Author: admin
tags: JavaScript  
const arr = [5, 10, 25, 15, 35, 20];
arr.splice(2).push(4, 2);
console.log(arr); // ??
What is now in the arr array?
Hint: the splice() method works in place: it affects the original array.
[5, 10, 25, 15, 4, 2]
[5, 10, 4, 2]
[5, 10]
[5, 10, 25, 15]
[]
[4, 2]
[25, 15, 35, 20, 4, 2]
[5, 10, 25, 15, 35, 20]
The arr array was changed only once.
The splice() method removed all the elements in it, starting from index 2, and returned a new array of deleted elements.
The push() method worked only with this returned array of deleted elements and did not change the arr array.
Rate the difficulty of the question:
easyhard