jeudi 4 juin 2015

Javascript length always returns true?

I am checking if arrays length is equal to 0. But no mather what I compare to, it always returns true inside if statement. Concrete example is below. I am comparing the array that is returned from google charts getSelection method. Although FireBug says the length of array that is returned from getSelection method is 0, if statement still returns true, no matter what.

ChartClickedEvent is the event handler that is fired when something is clicked inside google chart. Basically i try to figure out which chart was clicked and which column inside chart and get the details of the chart column from server. But the if statement is always true no matter the selection length. Tried also !==, === comparators, tried to merge two nested if statement into one, etc. No success. Any ideas? Thank you for help.

function ChartClickedEvent() {
    ChartObjects.forEach(function (entry) {
        var selection = entry.chart.getSelection();
        if (selection != null) {
            if (selection.length != 0) {
                GetDetails(entry, selection);
            }
        }
    })
}

Aucun commentaire:

Enregistrer un commentaire