JS:判断是否为数组

  1. var a=[];
    console.log(a.constructor)  //ƒ Array() { [native code] }

     

  2. var a=[];
    console.log(a instanceof Array)   //true

     

  3.  
    var a=[];
    var msg = Object.prototype.toString.call(a);
    +function(){
    	if(msg=="[object Array]"){
    		console.log('这是数组')
    	}else{
    		console.log('这不是数组')
    	}
    }();
    
    //这是数组

     

你可能感兴趣的:(js)