本文實例講述了JavaScript刪除數組元素的方法。分享給大家供大家參考。具體分析如下:
JS中可以通過delete刪除數組元素,但是刪除後數組的大小不會改變
<script type="text/javascript"> <!-- var days = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"]; document.write("Number of days:"+days.length); delete days[4]; document.write("<br />Number of days:"+days.length); //--> </script>
輸出結果
Number of days:7 Number of days:7
希望本文所述對大家的javascript程序設計有所幫助。