如何检查变量是否是JavaScript中的数组? [重复]

岁酱吖の 提交于 2020-08-10 15:45:18

问题:

This question already has an answer here: 这个问题在这里已有答案:

I would like to check whether a variable is either an array or a single value in JavaScript. 我想检查变量是JavaScript中的数组还是单个值。

I have found a possible solution... 我找到了一个可能的解决方案......

if (variable.constructor == Array)...

Is this the best way this can be done? 这是最好的办法吗?


解决方案:

参考一: https://stackoom.com/question/3Deo/如何检查变量是否是JavaScript中的数组-重复
参考二: https://oldbug.net/q/3Deo/How-do-you-check-if-a-variable-is-an-array-in-JavaScript-duplicate
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!