1. isArray
var arr = [1,2,3];
console.log( Array.isArray( arr ) );
<script>
var arr = [1,2,3];
var str = '你好';
console.log( Array.isArray( arr ) ); // true
console.log( Array.isArray( str ) ); // false
</script>
2. instanceof
var arr = [1,2,3];
console.log( arr instanceof Array );
<script>
var arr = [1,2,3];
var str = '你好';
console.log( arr instanceof Array ); // true
console.log( str instanceof Array ) ); // false
</script>
3. prototype
var arr = [1,2,3];
console.log( typeof Object.prototype.toString.call(arr).indexOf(Array) != -1 );
<script>
var arr = [1,2,3];
var str = '你好';
console.log( Object.prototype.toString.call(arr) ); // 打印出 [object Array]
console.log( typeof Object.prototype.toString.call(arr) ); // 打印出string
console.log( typeof Object.prototype.toString.call(arr).indexOf(Array) ); // 如果不是-1,就证明是数组
console.log( typeof Object.prototype.toString.call(arr).indexOf(Array) != -1 ); // 打印true或false
</script>
4. isPrototypeOf
var arr = [1,2,3];
console.log( Array.prototype.isPrototypeOf(arr) );
<script>
var arr = [1,2,3];
var str = '你好';
console.log( Array.prototype.isPrototypeOf(arr) );
</script>
5. constructor
var arr = [1,2,3];
console.log( arr.constructor.toString().indexOf('Array') > -1 );
<script>
var arr = [1,2,3];
console.log( arr.constructor.toString().indexOf('Array') > -1 );
</script>