1

问题:

返回一个数组被截断n个元素后还剩余的元素,从索引0开始截断。

解答:

function slasher(arr, howMany) {
// it doesn't always pay to be first
    var arrLength = arr.length;
    var spliceLength = arrLength - howMany;
    var spliceArr;
    
    spliceArr = arr.splice(howMany, spliceLength);
    
    return spliceArr;

}

slasher([1, 2, 3], 2);

链接:

https://www.w3cschool.cn/code...


冒泡的马树
194 声望14 粉丝

曾痴迷于赛博朋克世界的代码玩家一枚,