1

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);
  }
}

0

1 Answer 1

2

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);

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. It was very basic and I was very close to this push method. But could figure it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.