我得不到我想要的結(jié)果:Even Array is: 2, 18, 38, -10, 0, 104Odd Array is: 3, 13, -5, 11兩個(gè)數(shù)組,其中一個(gè)包含偶數(shù),另一個(gè)包含奇數(shù)。這是代碼: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我怎樣才能解決這個(gè)問題?
將數(shù)組分成兩個(gè)數(shù)組并將值設(shè)置為奇數(shù)和偶數(shù)
ibeautiful
2023-05-11 16:27:40