Blog

In JavaScript Create an Array with Odd Numbers
Posted on June 4, 2015 in Algorithms, JavaScript by Matt Jennings

Create an array with odd numbers from 1 to 255 and print out this array:

var y = [];

for(var i = 1; i < 256; i++) {
    if(i % 2 != 0) {
        y.push(i);
    }
}

console.log(y);

Leave a Reply