本文實(shí)例講述了JavaScript使用pop方法移除數(shù)組最后一個(gè)元素的用法。分享給大家供大家參考。具體如下:
下面的代碼演示了JS數(shù)組的pop方法,可以用來(lái)移除數(shù)組的最后一個(gè)元素,實(shí)際上就是把數(shù)組當(dāng)成堆棧使用
<!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>運(yùn)行結(jié)果如下:
Banana,Orange,Apple
希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注