I am looping inside a date. The snippet code below is a sample of what I have done so far. Apart from starting the loop it works fine
var = New date (2015, 0, 1); Var to = New Date (2015, 0, 10); While (from & lt; from) {to = new date (from .setdate (from.getDate (+ + 1)); Console.log (from.getDate ()); } // Output: 2, 3, 4, 5, 6, 7, 8, 9, 10 As you can see loop start at number 2 . I want to start it with 1 because I declared date var = new date (2015, 0, 1); I want the output to be 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 . What will happen to my code? Why does it start at 2 ?
Before you increase it's value Must use
var = new date (2015, 0, 1); Var to = New Date (2015, 0, 10); While (& lt; = from) {console.log (from.getDate ()); // It should be the last in the loop / from = new date (from .setdate (from.getDate (+ + 1)); From.setDate (from.getDate () + 1)} Demo:
No comments:
Post a Comment