Javascript Map iterate by for..of

Description

Javascript Map iterate by for..of

let myMap = new Map();
myMap.set(0, 'zero');
myMap.set(1, 'one');

for (let [key, value] of myMap) {
  console.log(key + ' = ' + value)
}

for (let key of myMap.keys()) {
  console.log(key)/*from w w  w .ja  v  a 2  s  .c  o  m*/
}

for (let value of myMap.values()) {
  console.log(value)
}

for (let [key, value] of myMap.entries()) {
  console.log(key + ' = ' + value)
}



PreviousNext

Related