How to shift and unshift using javascript?



How to shift and unshift using javascript?..

Answer / Aakriti Sharma

The shift() method removes the first element from an array and returns that element. The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array. For example: var arr = [1, 2, 3]; arr.shift(); // removes 1 and returns 1, arr.unshift(0); // adds 0 at the beginning and returns 4

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More JavaScript Interview Questions

How do you create array in javascript?

1 Answers  


What are the difference between undefined and not defined in javascript?

1 Answers  


What is the Infinity property used for in Javascript?

1 Answers  


What is JavaScript?

3 Answers  


What will be the output of the following code? //nfe (named function expression) var Foo = Function Bar() { return 7; }; typeof Bar();

1 Answers  


Why is javascript used for web pages?

1 Answers  


What are the uses of javascript in web page designing?

1 Answers  


What is Javascript namespacing? How and where is it used?

1 Answers  


Is it possible make a call to server side event of any button using javascript?

1 Answers  


what is the purpose of using jsp?

1 Answers  


Which is better for or foreach in javascript?

1 Answers  


What are the primitive data types in JavaScript?

1 Answers  


Categories