标题 | JavaScript使用pop方法移除数组最后一个元素用法实例 |
内容 | 下面的代码演示了JS数组的pop方法,可以用来移除数组的最后一个元素,实际上就是把数组当成堆栈使用 <!DOCTYPE html> <html> <body> <p id="demo"> Click the button to remove the last array element. </p> <button onclick="myFunction()">Try it</button> <script> var fruits = ["Banana","Orange","Apple","Mango"]; function myFunction() { fruits.pop(); var x=document.getElementById("demo"); x.innerHTML=fruits; } </script> </body> </html> 运行结果如下: Banana,Orange,Apple |
随便看 |
|
在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。