Saturday, September 29, 2018

Javascript some quirks

the first one is for loop. In the below, the value idx is index into the array and not the object itself. coming from

for (idx in result){
    var obj = result[idx];
}

another surprise was the year from Date object

var sDate = startTimeField.getYear() +"-"+(startTimeField.getMonth()) +"-"+ startTimeField.getDate();

the output is 118-8-29, though expected outcome was 2018-9-29

Below code gives this result. getFullYear is different from getYear!

var sDate = startTimeField.getFullYear() +"-"+(startTimeField.getMonth()+1) +"-"+ startTimeField.getDate();


No comments:

Post a Comment