Consider the following code snippet :
var a = []; a.unshift(1); a.unshift(22); a.shift(); a.unshift(3,[4,5]); a.shift(); a.shift(); a.shift();
The final output for the shift() is
A.1
B.[4,5]
C.[3,4,5]
D.Exception is thrown
Answers
Answered by
1
Hi there,
Option A is correct.
Explanation : The unshift() and shift() methods behave much like push() and pop(), except that they insert and remove elements from the beginning of an array rather than from the end. unshift() adds an element or elements to the beginning of the array, shifts the existing array elements up to higher indexes to make room, and returns the new length of the array. shift() removes and returns the first element of the array, shifting all subsequent elements down one place to occupy the newly vacant space at the start of the array.
Option A is correct.
Explanation : The unshift() and shift() methods behave much like push() and pop(), except that they insert and remove elements from the beginning of an array rather than from the end. unshift() adds an element or elements to the beginning of the array, shifts the existing array elements up to higher indexes to make room, and returns the new length of the array. shift() removes and returns the first element of the array, shifting all subsequent elements down one place to occupy the newly vacant space at the start of the array.
Answered by
1
var a = []; a.unshift(1); a.unshift(22); a.shift(); a.unshift(3,[4,5]); a.shift(); a.shift(); a.shift();
The final output for the shift() is 1
The answer is 1
The final output for the shift() is 1
The answer is 1
Similar questions
Computer Science,
7 months ago
English,
7 months ago
English,
7 months ago
Computer Science,
1 year ago
Computer Science,
1 year ago
Science,
1 year ago