Programming Tips - javaScript: enumerate all items in a javaScript associative array

Date: 2009jun29 Date: 2025jul1 Language: javaScript Level: beginner Q. javaScript: enumerate all items in a javaScript associative array Is there a foreach like some other languages? A. There is no foreach, this is how you do it in javaScript:
function allInAssociativeArray() { const a = { one: 1, two: 2, three: 3 }; let key, val; for (key in a) { val = a[key]; document.writeln('a[' + key + ']=' + val + '<br>'); } }