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);
}
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);
}
js foreach key value
Object.keys(obj).forEach(function (key) {
// do something with obj[key]
});
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']
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us