截取js數組中某段值(slice)


// var a = [1,2,3];

//
console.log(a.slice(1)); >>[2, 3] 從索引1開始截取。 // console.log(a.slice(1,2)); >>[2] 從索引1可以截取到索引2之間的值 // console.log(a.slice(0,2)); >>[1,2] 從索引0開始截取到索引2之間的值 // console.log(a.slice(-1)); >>[3] 從末尾-1索引截取一個值 // console.log(a.slice(0,-1)); >>[1,2] 從索引0開始截取到末尾索引-1的值

 


免責聲明!

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



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