① 通过typeof 加长度判断;

② 通过instanceof判断,不过有判断顺序;

 

以下为示例:

var judgeType1 = function(o){
    if(typeof o == 'object'){
       if(typeof o.length == 'number'){
           alert('变量类型为 Array')
           return
       }
        alert('变量类型为 Object')
        return
    }
    alert('变量类型不为 Object')
}
var judeType2 = function(o){
   if(o instanceOf Array){
        alert('变量类型为 Array')
   }else if(o instanceOf Object){
       alert('变量类型为 Object')
   }else{
       alert('变量类型不为 Object')
   }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-02-19
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
猜你喜欢
  • 2022-12-23
  • 2021-12-06
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案