In JavaScript how to detect weather the type is Array or Object?
本问题已经有最佳答案,请猛点这里访问。
我需要知道如何检查变量是数组还是对象
1 2 3 4 5 6 7 8 9 10 | var arr = ['foo', 'bar']; var obj = { 0: 'foo', 1: 'bar' } document.write('arr is an: ' + typeof arr + ', obj is an: ' + typeof obj) // The result is always: // arr is an: object, obj is an: object |
有什么方法可以区分这两种类型吗?