Currently, I am grappling with understanding the syntax required to iterate through a map in Typescript. All the keys in this particular map are strings, while the values associated with them consist of arrays of strings.
Below is an excerpt of the sample code:
let attributeMap: Map<string, string[]> = new Map<string, string[]>();
// Sample data
let sampleKey1 = "bob";
// Filling up the 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);
// Attempting to loop through the map
for (let key in attributeMap) {
console.log(attributeMap.get(key));
console.log("WE'RE IN THE MAP!");
}
console.log("done");
Upon running this code as it stands, only "done" gets displayed. Nothing from within the map is printed, and neither does the message "WE'RE IN THE MAP" appear. It seems that the for loop isn't being executed at all. Can anyone shed light on why this is happening and provide insights on how to rectify this issue?