I am relatively new to Angular and Typescript and I am running into an issue with variable scope. I am looking to call a function to return an array of image paths and then set those to a different array variable.
    ngAfterContentInit() {
        const minImages = 6;
        const tempImgArr = this.getAllImages(function (imgArr){
            // randomize image order
            imgArr = shuffleArray(imgArr);
            //cut to 6
            imgArr = imgArr.slice(0,minImages);
            console.log(imgArr);   // this displays the correct data
            return imgArr;
        });
      console.log(tempImgArr);   // this shows undefined
    }
    getAllImages(cb) {
      let arrAllImg = [];
      this.http.get<any>(this.backendPath+"/api/").subscribe(
        data => {  
            data.forEach(e => {
                var apiObj = {
                    path: e.Media1,
                    txt: e.MessageTxt
                }
                arrAllImg.push(apiObj);
            });
            cb(arrAllImg);
        },
        error => {
            console.error('There was an error!', error)
            cb(arrAllImg);
        }
      )
    }
How can I define my tempImgArr to return the appropriate array?
 
    