js如何刪除陣列的倒數第n個及後面元素
阿新 • 來源:網路 • 發佈:2022-05-28
方法:如刪除倒數第n個元素:使用splice(list.length-n)即可
要求:刪除list的倒數第2個及後面元素
let list =[10,5,7,8,4,3];
list.splice(list.length-2);
console.log(list);//[10,5,7,8,4]
方法:如刪除倒數第n個元素:使用splice(list.length-n)即可
要求:刪除list的倒數第2個及後面元素
let list =[10,5,7,8,4,3];
list.splice(list.length-2);
console.log(list);//[10,5,7,8,4]