js中区分数组和对象
一、通过instance of来识别
[] instance of Array //true
{} instance of Array //false
二、通过Object,prototype.toString.call方法来识别
Object.prototype.toString.call([]) //["object Array"]
Object.prototype.toString.call({}) //["object Object"]
三、通过ES6中的Array.isArray来识别
Array.isArray([]) //true
Array.isArray({}) //false
四、通过调用constructor来识别
{}.constructor //返回object
[].constructor //返回Array
链接: https://blog.csdn.net/hu_lanlan/article/details/79872451.