for of map js code example

Example 1: loop through map in js

const object = {'a': 1, 'b': 2, 'c' : 3};
for (const [key, value] of Object.entries(object)) {
  console.log(key, value);
}

Example 2: javascript map

function listFruits() {
  let fruits = ["apple", "cherry", "pear"]
  
  fruits.map((fruit, index) => {
    console.log(index, fruit)
  })
}

listFruits()

// https://jsfiddle.net/tmoreland/16qfpkgb/3/

Example 3: js loop trough map

for (let key of map) {
	console.log(key);
}

Example 4: javascript map

The map() method creates a new array with the results of calling a provided function on every element in the calling array.