我想使用超出其范围的“标签”变量,我该怎么做?我知道这不是一个好习惯,但我仍然想使用标签数组中的值。我尝试克隆变量,但范围问题仍然存在
const client = new vision.ImageAnnotatorClient();
// Performs label detection on the image file
client
.labelDetection(`${filename}`)
.then(results => {
var labels = results[0].labelAnnotations;
console.log('Labels: ');
labels.forEach(label => console.log(label.description));
})
.catch(err => {
console.error('ERROR: ', err);
});
编辑1: 我想以这种方式使用标签
const client = new vision.ImageAnnotatorClient();
// Performs label detection on the image file
client
.labelDetection(`${filename}`)
.then(results => {
var labels = results[0].labelAnnotations;
console.log('Labels: ');
labels.forEach(label => console.log(label.description));
})
.catch(err => {
console.error('ERROR: ', err);
});
console.log('Labels: ');
labels.forEach(label => console.log(label.description));
但控制台显示错误“Cannot use undefined for forEach”