Please help me remove the extra bracket that shows up when I console log. I've been trying for hours to remove it to no avail. This is my code:
let numberArray = [];
let evenNumbers = [];
let oddNumbers = [];
function findOdds(numberArray) {
for (let i = 0; i < numberArray.length; i++) {
if ((numberArray[i] % 2) !== 0) {
oddNumbers.push(numberArray[i]);
}
else {
evenNumbers.push(numberArray[i]);
}
} console.log(oddNumbers);
};
findOdds(numberArray);
findOdds([90023, 11811, 10032, 10026, 67021]);
When I console log it I get this:
[]
[ 90023, 11811, 67021 ]
How do I remove that extra first bracket?
You can delete this line :
findOdds(numberArray);
You run your function twice and the first bracket is logged here when you're running your function with an empty array as parameter.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments