我得不到我想要的结果:Even Array is: 2, 18, 38, -10, 0, 104Odd Array is: 3, 13, -5, 11两个数组,其中一个包含偶数,另一个包含奇数。这是代码:let arrayMain = [2, 3, 13, 18, -5, 38, -10, 11, 0, 104];let oddArray = [];let evenArray = [];for (let i = 0; i < arrayMain.length; i++){ if (i % 2 == 0) { evenArray.push(arrayMain[i]); } else { oddArray.push(arrayMain[i]); }}console.log("Odd Array is " + oddArray);console.log("Even Array is " + evenArray);它给了我:Odd Array is 3,18,38,11,104Even Array is 2,13,-5,-10,0我怎样才能解决这个问题?
添加回答
举报
0/150
提交
取消