Javascript parseFloat and nulls

I am very new to javascript, since I am currently doing a cross-platform web application in jQuery Mobile, I used the XML Parsing example for the HighCharts chart, but when I came across a null value in my raw data, it could not draw any either line and turns it into a scatter plot of almost.

// push data points $(series).find('data point').each(function(i, point) { seriesOptions.data.push( parseFloat($(point).text()) ); }); 

I have no idea how to write an if statement that checks to see if it found a zero, and if so, then tell him to use it ... Can someone please help or call me in the right direction, as I would wanted my charts to be correct and not to put a null value where i have zero.

+4
source share
3 answers

With a quick google in Javascript If the statutes I believe, I got there - thanks Bjorn: 0) Your answer made me get there !!!

 // push data points $(series).find('data point').each(function(i, point) { var floatVal = parseFloat($(point).text()); if (!isNaN(floatVal)) { seriesOptions.data.push(floatVal); } else { seriesOptions.data.push(null); } console.log(floatVal) }); 
0
source

Well, parseFloat will return "NaN" if it is not a number (null and undefined are NaN), so you can try to do like this:

 // push data points $(series).find('data point').each(function(i, point) { var floatVal = parseFloat($(point).text()); if (!isNaN(floatVal)) { seriesOptions.data.push(floatVal); } }); 
+4
source

A null check JavaScript, like any other C-style language:

  if (thing == null) 

or

  if (thing != null) 

I believe that this works well in most cases against my own programming, where I write, as I, for example, in C #; however, I find that other people's code is based on things that have never been announced or installed, and the like, and, in general, it comes down to spaghetti checking null and "undefined" - yes, a literal line, really - and everything else .

+1
source

All Articles