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] }
![](https://img2020.cnblogs.com/blog/1341628/202008/1341628-20200806093149467-663773028.png)
判断数据类型是否为Array
[1,2,3,4].constructor.toString().indexOf("Array") > -1;