如何删除' RemoveThis'然后选择每0(删除第一项后每第2项)?
var newItems = "RemoveThis,1,0,1,0,1,0,1,0,1,0,1,0",
everyThirdItem = newItems.split(",")
.filter(function(_, idx) { return ((idx + 1) % 2) === 0 });
console.log(everyThirdItem)
答案 0 :(得分:3)
使用Array#slice
获取除第一个之外的剩余元素。
var newItems = "RemoveThis,1,0,1,0,1,0,1,0,1,0,1,0",
everyThirdItem = newItems.split(",")
.slice(1)
.filter(function(_, idx) {
return ((idx + 1) % 2) === 0
});
console.log(everyThirdItem)

或者更新过滤条件以避免使用第一个元素。
var newItems = "RemoveThis,1,0,1,0,1,0,1,0,1,0,1,0",
everyThirdItem = newItems.split(",")
.filter(function(_, idx) {
return idx != 0 && idx % 2 === 0
});
console.log(everyThirdItem)