js 獲取數組最后一個元素


當然有很多中做法 我這邊就隨便寫幾個最常用 最簡單的方法把

 1  # shift
 2  刪除數組第一個元素,並返回該元素,跟pop差不多    
 3  var a =  ["aa","bb","cc"];
 4  document.write(a.shift());  // -> aa
 5  document.write(a);    // -> bb,cc
 6  當數組為空時,返回undefined
 7  
 8  # pop
 9  刪除數組最后一個元素,並返回該元素
10  var a =  ["aa","bb","cc"];
11  document.write(a.pop());  // -> cc
12  document.write(a);    // -> aa, bb
13  
14  # arra_update 數組
15   var arra_update_new = arra_update[arra_update.length - 1];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM