Answers for "how to iterate map object in javascript"

0

iterate over map key value javascript

recipeMap.forEach((value, key) => {
	console.log(`${key} costs ${value}`);
});
Posted by: Guest on December-02-2020
-1

js foreach key value

Object.keys(obj).forEach(function (key) {
   // do something with obj[key]
});
Posted by: Guest on March-22-2020
0

javascript map foreach

const myArray = ['Sam', 'Alice', 'Nick', 'Matt'];

// Appends text to each element of the array
const newArray = myArray.map(name => {
	return 'My name is ' + name; 
});
console.log(newArray); // ['My name is Sam', 'My Name is Alice', ...]

// Appends the index of each element with it's value
const anotherArray = myArray.map((value, index) => index + ": " + value);
console.log(anotherArray); // ['0: Sam', '1: Alice', '2: Nick', ...]

// Starting array is unchanged
console.log(myArray); // ['Sam', 'Alice', 'Nick', 'Matt']
Posted by: Guest on August-26-2020

Code answers related to "how to iterate map object in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language