I am trying to understand the syntax for iterating through a map in Typescript. The keys in my map are strings. The values are arrays of strings.
Here is some sample code:
let attributeMap: Map<string, string[]> = new Map<string, string[]>();
// sample data
let sampleKey1 = "bob";
// populate map
let value: string[] = attributeMap.get(sampleKey1) || [];
value.push("clever");
attributeMap.set(sampleKey1, value);
value = attributeMap.get(sampleKey1) || [];
value.push("funny");
attributeMap.set(sampleKey1, value);
// try looping through the map
for (let key in attributeMap) {
console.log(attributeMap.get(key));
console.log("WE'RE IN THE MAP!");
}
console.log("done");
When I run this code, the only thing printed is "done".
Why is it that nothing in the map gets printed, nor does the message "WE'RE IN THE MAP"? It's as if the for loop is never entered. Why is that and how would I fix that?