I am using Visual Studio Code. I am trying to return an array with only odd numbers using JavaScript. This is the code:
function oddCouple(arr) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] % 2 == 0) {
delete arr[i];
}
}
return arr;
}
console.log(oddCouple([2, 6, 7, 0, 1, 3, 7, 5]));
This is what I am getting. I do not want the empty items, just odd numbers.
[ <2 empty items>, 7, <1 empty item>, 1, 3, 7, 5 ]