What are the stack methods of JavaScript
This article will explain in detail what the stack methods of JavaScript are, and the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
1. Push receives any number of parameters.
Add one by one to the end of the array and return the modified array length.
2. Pop removes the last item from the end of the array.
Lower the value of the array, and then return to the removed item.
3. Shift removes the first item in the array and returns it, reducing the length of the array by 1.
4. Unshift adds any items at the front of the array and returns the length of the new array.
Example
Var colors = new Array (); / / create an array var count = colors.push ("red", "green"); / / push in two items alert (count); / / 2 return array length var item = colors.pop (); / / get the last item alert (item); / / "green" alert (colors.length); / / 1 var item1 = colors.shift (); / / get the first alert (item1) / / "red" alert (colors.length); / 0 var count1 = colors.unshift ("red", "green"); / / the array pushes forward two items of alert (count1); / / 2 the stack methods of JavaScript are shared here. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.