Using for..of loop on ES6 Map

for (var [key, value] of myMap) {
    console.log(key + " = " + value);
}

is like

for (let pair of myMap) {
    var [key, value] = pair;
    console.log(key + " = " + value);
}

So it’s not myMap that has to be an array for the destructuring to work; rather, each of its elements has to be an array when it’s iterated over, and iterating over a map indeed produces arrays (key/value pairs).

Map#forEach’s argument order is probably for consistency with Array#forEach, which calls the function with arguments (item, index); it, in turn, probably does that because you don’t always need the index.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)