I have an array called yourArray, defined as var yourArray = [];
. My goal is to populate this array with object names retrieved from the s3 using listObjects.
var params ={
Bucket: 'exBucket',
Prefix: 'somePrefix'
};
s3.listObjects(params, function(Err, Data){
if(!Err){
for (var i = 0; i < Data.Contents.length; i++){
console.log('Listed: ', Data.Contents[i].Key);
yourArray.push(Data.Contents[i].Key);
}
};
});
While
console.log('Listed: ', Data.Contents[i].Key);
prints all the names correctly, yourArray.push(Data.Contents[i].Key);
fails to add the names and leaves the array empty. What am I doing wrong?