JavaScript【引用类型】栈方法

以下为学习《JavaScript 高级程序设计》》(第 3 版) 所做笔记。

栈是一种后进先出的数据结构。栈中项的插入与移除只发生在栈的顶部。ECMAScript为数组专门提供了 push() 跟 pop() 方法,以便实现类似栈的行为。

 1 <script>
 2     var arr1 = ["a","b","c",undefined,null];
 3     //push()
 4     //插入项
 5     //返回插入后数组的长度
 6     console.log(arr1.push("e","f"))        //输出:7
 7     console.log(arr1);                    //输出:(7) ["a", "b", "c", undefined, null, "e", "f"]
 8 
 9     //pop()
10     //移除数组最后一项
11     //返回数组最后一项
12     console.log(arr1.pop())                //输出:f
13     console.log(arr1);                    //输出:(6) ["a", "b", "c", undefined, null, "e"]
14 </script>

push()

  从 数 组 末 端 添 加 项

pop()

  从 数 组 末 端 移 除 项

原文地址:https://www.cnblogs.com/xiaoxuStudy/p/12246842.html