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

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -