in JavaScript by

What will be the output obtained by "shift ()" in the given code of JavaScript?

var a =[];  








a) Exception is thrown

b) [4,5]

c) [3,4,5]

d) 5

1 Answer

0 votes

Answer: D

Reason: In JavaScript, the "unshift()"," shift()" methods work like just as push() and pop() but with a slight change, unlike the push and pop the unshift(), unshift() both insert and remove a data item from the beginning instead of from the end of the array. The "unshift()" is used for inserting the data element/item in the beginning of the array while the "shift()" method shifts the data item to the beginning of the array from the higher index, empty the last index of the array and returns the updated length of the array.

In the process of shifting, the data element is removed from the beginning of the array, and all subsequent elements are shifted and the new length of the array is returned.

Related questions

0 votes
asked Mar 23, 2021 in JavaScript by sharadyadav1986
0 votes
asked Mar 24, 2021 in JavaScript by sharadyadav1986
+1 vote
asked Mar 22, 2021 in JavaScript by Robindeniel