arrays - Why would character or string be considered falsy in javascript -


hey guys been racking brain , reading articles on subject , have read stated "some string" or "a" considered truthy, when wrote code test array filter out falsy items kept saying strings , characters falsy. know how fix issue using .filter(boolean) know why code wouldn't work here code

function bouncer(arr) {    // don't show false id bouncer    var idvar = [];    for(var = 0; i<arr.length + 1;i++)     {            if(arr[i] === false|| arr[i]===0 || arr[i]==="" || arr[i]===null || arr[i]===undefined || isnan(arr[i]) === true)        {           alert(arr[i]);        }      else        {          idvar.push(arr[i]);        }    }   alert(idvar + " one");  }    bouncer([1,"some string"]);

the isnan(arr[i]) === true causing pass. "some string" coerced number , isnan evaluate true.

see https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/isnan#examples


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -