Why NodeJS says that an Array is an Object?
本问题已经有最佳答案,请猛点这里访问。
我的代码有什么问题?
1 2 3 4 5 6 | let x = ['hello',1] let y = [2] let z = {x:"hello",y:2} console.log("type of x:",typeof x) // expected array! console.log("type of y:",typeof y) // expected array! console.log("type of z:",typeof z) // expected object, ok |
结果:
1 2 3 | type of x: object type of y: object type of z: object |
因为javascript数组是对象。
您可以使用EDCOX1×0函数来检查值是否为数组。