Last active
December 14, 2015 15:09
-
-
Save silvers/5105631 to your computer and use it in GitHub Desktop.
obj.length === +obj.length
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var test = function(obj) { | |
console.log(obj); | |
console.log(obj.length); | |
console.log(+obj.length); | |
if (obj.length === +obj.length) { | |
console.log("array!!!"); | |
} else { | |
console.log("object!!!"); | |
} | |
}; | |
test([1,2,3,4,5]); | |
test({a:1,b:2,c:3}); | |
/* node length.js | |
[ 1, 2, 3, 4, 5 ] | |
5 | |
5 | |
array!!! | |
{ a: 1, b: 2, c: 3 } | |
undefined | |
NaN | |
object!!! | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
obj maybe not a Object. maybe
arguments
. maybevar obj = {length: 5}