标签:style blog color os io ar cti div
判断一个玩意是不是数组:
(1)新方法:Array.isArray();
(2)旧方法:toString();
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>isArray(value)</title>
<script>
function isArray(value){
// ECMAScript5 方法
if(typeof Array.isArray==="function"){
return Array.isArray(value);
}else{
return Object.prototype.toString.call(value)==="[object Array]";
}
}
alert([]==false) // true
alert(Array.isArray) // ie6,7,8为undefined
alert(isArray([])) // true
alert([]==[]) // false
</script>
</head>
<body>
</body>
</html>
当然,也可以简写成三目格式。
标签:style blog color os io ar cti div
原文地址:http://www.cnblogs.com/ccforeverd/p/3907996.html