I want to use the "labels" variable beyond its scope, how can I do it ? I know its not a good practice but I still want to use the values in labels array. I tried cloning the variable but the scope issue persists
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);
});
EDIT 1: I want to use the label this way
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));
But the console shows the error "Cannot use undefined for forEach"