js 判断数据类型

function getType(variable) 
return typeof variable === 'object' ? Object.prototype.toString.call(variable).replace('[object ', '').replace(']', '').toLowerCase() : typeof variable; }

 const numArr = [1,2,3];
 getType(numArr); //array
 

 判断数据类型是否为Array

[1,2,3,4].constructor              // 返回函数 Array()   { [native code] }

    判断数据类型是否为Array

[1,2,3,4].constructor.toString().indexOf("Array") > -1;

参考地址    https://www.cnblogs.com/xinggood/p/6568624.html  

posted @ 2020-07-20 15:27  氧化成风  阅读(110)  评论(0)    收藏  举报