Currently, I am dealing with a test array where the initial value is set to null.
In my function, I am making some modifications to the test array. However, even though I am reassigning values to it, the console still shows it as a null or undefined array.
abcd(){
this.dataService.getAirport().subscribe(
(data) => {
this.airportData = data.data.data.metaDataRows;
this.countryData = data.data.data.metaDataFields[0].column;
const airConNames = this.countryData.values;
this.test = [];
this.test.push({name:'Select a Country', id:'0'});
//this.test = [{name:'Select a Country', id:'0'}];
console.log(this.test);
airConNames.forEach(function(entry) {
//console.log(entry.name);
//console.log(entry.country_id);
this.test = [{name : entry.name, id : entry.country_id}];
});
console.log(this.test); // this is null
},
(error) => {
this.dataService.handleServiceError(error.message, this.TAG);
}
);
console.log(this.test); //this is null
}
Despite my efforts, the console continues to display null for the test array.
I am seeking assistance in identifying where I may have made an error in my code.