在node.js中,Array.isArray = true,但是array.length = undefined

时间:2017-11-30 09:32:26

标签: javascript arrays node.js

我注意到该数组不返回元素数:

console.log('INFO : Condition: %s', JSON.stringify(entries[0].conditions))
console.log('INFO : Condition isArray - %s', Array.isArray(entries[0].conditions))
console.log('INFO : Condition cnt - %s', entries[0].conditions.lenght)
console.log('INFO : Condition[0]: %s', JSON.stringify(entries[0].conditions[0]))
var actionConditions = entries[0].conditions
console.log('INFO : Condition cnt - %s', actionConditions.lenght)

控制台输出:

[11:15:55.679] INFO : Condition: [{"type":"state","attribute":"below","entity":"wkor2Xf3h3GQ7vnj","value":"1200"}]
[11:15:55.680] INFO : Condition isArray - true
[11:15:55.681] INFO : Condition cnt - undefined
[11:15:55.682] INFO : Condition[0]: {"type":"state","attribute":"below","entity":"wkor2Xf3h3GQ7vnj","value":"1200"}
[11:15:55.683] INFO : Condition cnt - undefined

有人可以指出我的问题/解决方案吗? THX!

1 个答案:

答案 0 :(得分:2)

你可以尝试

console.log('INFO : Condition cnt - %s', entries[0].conditions.length)
//                                                                 ^^