ElDiabolo
ElDiabolo

Reputation: 376

Return Result AFTER foreach in ionic?

let arrData = [];
arrGotData.forEach(function(objGotData) {
            let arrDataLength = arrData.length;
            //do something
            arrData[arrDataLength] = objGotData;
}
return arrData;

How could I return my arrData AFTER the forEach got executed and not before?

Upvotes: 0

Views: 126

Answers (1)

Amit Chigadani
Amit Chigadani

Reputation: 29715

You are missing the bracket ) after }

Check out the working code here

Adding the same code here for reference

fun() {
    let arrData = [];
    this.arrGotData.forEach((objGotData) => {   
    let arrDataLength = arrData.length;
    //do something
    arrData[arrDataLength] = objGotData;
   });   
    return arrData; 
}

Upvotes: 1

Related Questions