Re: Question about string.trim()ã By: echicken to KenDB3 on Thu Sep 08 2016 11:39 amãã >> So, my first question is, is the trim() function valid in JavaScriptã >> 1.8.5? I'm guessing it is because it's been working inãã ec> Yes, it's a valid method on a String object.ããAwesome, thank you.ãã >> What I find interesting is that the error flagged on a trim() on lineã >> 275, but was OK with the trim() on line 270: timestamp.trim(). ãã ec> In this case 'timestamp' is really just another String, since you're justã ec> grabbing the text from the feed and not turning it into a Number or Dateã ec> object, so that makes sense.ãã ec> My best guess is that the 'solarflux' value was absent when this personã ec> fetched the feed, or that they failed to fetch the feed altogether. Onã ec> line 80, if 'solardata.solarflux' is undefined, 'sfi' gets set to 0, aã ec> Number, which does not have the '.trim()' method. Wrap that 0 in quotes onã ec> line 80 and this particular problem should go away.ãã ec> Also, if you wanted to, you could also shorten things a bit by doingã ec> something like:ãã ec> var sfi = solardata.solarflux || '0';ã ec> var sfi_int = parseInt(sfi);ã ec> var ai = solardata.aindex || 'No Data';ã ec> // etc.ãã ec> That would be like a shorter version of:ãã ec> var sfi = (typeof solardata.solarflux == 'undefined' ? '0' :ã ec> solardata.solarflux);ãã ec> Which is a shorter version of:ãã ec> var sfi = solardata.solarflux;ã ec> if (sfi == undefined) {ã ec> var sfi = '0';ã ec> }ããYou make it look so easy! Thanks man, that's incredibly helpful, I reallyãappreciate it. I'm learning lots playing with this stuff. I had a feeling, butãI wasn't sure. ããUpdates imminent :-)ãã~KenDB3ãã---ã þ Synchronet þ KD3net-Rhode Island's only BBS about nothing.
http://bbs.kd3.usã