标签:span ble null filter undefined value code class script
真假美猴王!
删除数组中的所有假值。
在JavaScript中,假值有false
、null
、0
、""
、undefined
和 NaN
。
/* console.log(Boolean(0)); // false console.log(Boolean(-0)); // false console.log(Boolean(‘0‘)); // true console.log(Boolean(false)); // false console.log(Boolean(‘false‘)); // true console.log(Boolean(true)); // true console.log(Boolean(‘true‘)); // true console.log(Boolean(null)); // false console.log(Boolean(NaN)); // false console.log(Boolean(undefined));// false console.log(Boolean(‘‘)); // false console.log(Boolean(1)); // true console.log(Boolean(-1)); // true console.log(Boolean(3)); // true console.log(Boolean("w3cplus"));// true */ function bouncer(arr) { return arr.filter( function( value ){ return value; }); } bouncer([‘sd‘, "ate", "a", false, 9]);
标签:span ble null filter undefined value code class script
原文地址:http://www.cnblogs.com/fffangrui/p/6099398.html