I have a service which populates my associative array in typescript,
fun populateData(){
let tempArr;
tempArr = [];
this.service.get('Post', 1, 'true').subscribe(
(response) => {
this.loadingIcon = false;
for (let i = 0; i < response.results.length; i++) {
tempList = response.results[i]['tags'];
for ( let iter of tempList){
if ( iter in tempArr) {
tempArr[iter] = tempArr[iter] + 1;
}else {
tempArr[iter] = 1;
}
}
}
},
(error) => {
if (error['status'] === 401) {
localStorage.clear();
this.router.navigateByUrl('/login');
} else {
this.router.navigateByUrl('/error');
}
}
);
console.log(tempArr);
/*
This function is inside a class, once I iterate get access to tempArr I will be assigning the tempArr data to a class variable like
for (items in tempArr){
this.data.push(items, tempArr[items]);
}
*/
}
I'm able to populate my associative array with the service above which gives the following output in console,
I'm not able to iterate through this array, I tried a couple of methods like the following,
for ( const key in tempArr) {
console.log(key + ':' + tempArr[key]);
}
I want both they key and values from the array.

tempArris constructedarraybut rather plain object, and to iterate through all pairs of (key, value) you can use ES7Object.entriesmethod.