判断变量是数组还是对象,使用Object.prototype.toString.call(),兼容性好,切勿使用typeof来判断对象或者数组,因为typeof得到的都是object;

function isObjArr(value){
     if (Object.prototype.toString.call(value) === "[object Array]") {
            console.log('value是数组');
       }else if(Object.prototype.toString.call(value)==='[object Object]'){
            console.log('value是对象');
      }
}
function isObjArr(value){
     if (Object.prototype.toString.call(value) === "[object Array]") {
            console.log('value是数组');
       }else if(Object.prototype.toString.call(value)==='[object Object]'){
            console.log('value是对象');
      }
}

相关文章:

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