constuctor
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var obj = {};
function isArray(myArray) {
return myArray.constructor.toString().indexOf("Array") > -1;
}
console.log(isArray(fruits)); //true
console.log(isArray(obj)); //false
</script>
Object.prototype.toString.call()
console.log(Object.prototype.toString.call(fruits)); //[Object Array]
instanceof
console.log(fruits instanceof Array);
网友评论