Here's my code:
var myArray = new Array();
for (var i = 0; i < 24; i++ ){
myArray.push([i]);
}
How can I add/replace null values where there's 1, 3, 5, 7, 9...... ?
For prime numbers and null:
var arr = [], i, j, primeNum = [];
for (i = 2; i <= 24; ++i) {
if (!arr[i]) {
primeNum.push(i);
for (j = i << 1; j <= 24; j += i) {
arr[j] = true;
}
} else {
primeNum.push(null);
}
}
console.log(primeNum)
If you just want the odd numbers as null:
var arr = [];
for (var i = 0; i < 24; i++ ){
if( i % 2 === 1){
arr.push(null);
} else {
arr.push(i);
}
}
console.log(arr)
nullvalue the prime number and you are done. Edit : plus, I quickly took a look at mathsisfun.com/prime_numbers.html and it seems not to be what you say. Did you mistake with odd and even numbers ?