Reputation: 2685
I'm able to get 5 value from for loop and I all values to be in the array.
Values are coming:
2020
2024
2028
2032
2036
It shold be like this:
var years= [2020, 2024, 2028, 2032, 2036];
var td = new Date();
var cy = td.getFullYear();
ily_modulo = function(yr) {
return !((yr % 4) || (!(yr % 100) && (yr % 400)))
}
var yLepa=[];
for (var yr = cy; yr <= cy+20; yr++) {
if(ily_modulo(yr) == true){
console.log(yr);
}
}
Upvotes: 1
Views: 41
Reputation: 41893
You want to store results inside an array? If so, just push the results inside the yLepa
array, instead of loging it to the console with every iteration.
var td = new Date();
var cy = td.getFullYear();
ily_modulo = function(yr) {
return !((yr % 4) || (!(yr % 100) && (yr % 400)))
}
var yLepa = [];
for (var yr = cy; yr <= cy + 20; yr++) {
if (ily_modulo(yr) == true) {
yLepa.push(yr);
}
}
console.log(yLepa);
Upvotes: 2