I want to sort the array and to store the fetched values into a new array for print. I tried with push() but there is an error is occurring and shows that" Cannot read property 'push' of undefined".
`
this.dataService.userprofile().subscribe((data:any) => {
let profile:any[]=data.profiles;
for(let index=0;index<profile.length;index++) {
const element = profile[index];
const today: number = Date.now();
var b = Math.abs(today - Date.parse(element["dob"]));
element["dob"] = Math.floor(b / (1000 * 3600 * 24 * 365.25));
if (element["active"]=="N"){
this.row.push(element);
}}
this.rowData = this.row;//ag-grid row
console.log(this.rowData)
})
`
this.rowinitialized in any way in the context of your function ?this.row = (this.row || []).concat(element);rowis a local variable to store the array ofelements and populate the initializedthis.rowData.. In my answer i suggest to work directly withthis.rowDataassigning the result ofArray.prototype.reduce()