我是不是傻了? (我来自 Ruby,所以我可能缺少一些有关 Javascript 数组的内容)。
console.log(new_devices)
控制台结果:Array[1]
.
console.log(new_devices.length)
控制台结果:0
生成此代码的代码:
var sp = require('serialport');
var new_devices = [];
sp.list(function(err, ports) {
ports.forEach(function(current) {
if (current.manufacturer == "Teensyduino") {
new_devices.push(current);
}
});
});
console.log(new_devices);
console.log(new_devices.length);
最佳答案
关于Javascript 数组计数与控制台不一致?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39547992/