我想在
Javascript中删除数组中的每个第二和第三个元素.
我的数组看起来像这样:
var fruits = ["Banana","yellow","23","Orange","orange","12","Apple","green","10"];
现在我想删除每个第二和第三个元素.结果如下所示:
["Banana","Apple"]
我试图使用for-loop和splice:
for (var i = 0; fruits.length; i = i+3) { fruits.splice(i+1,0); fruits.splice(i+2,0); };
当然,这会返回一个空数组,因为在循环仍然执行时会删除元素.
我该怎么做才能正确?
谢谢.