DekGenius.com
JAVASCRIPT
js map iterate
map = new Map();
map.set('key1', 'value1');
map.set('key2', 'value2');
for (let [key, value] of map.entries()) {
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);
}
javascript Iterate Through a Map
let map1 = new Map();
map1.set('name', 'Jack');
map1.set('age', '27');
// looping through Map
for (let [key, value] of map1) {
console.log(key + '- ' + value);
}
Iterate over map in javascript
let map = new Map();
map.set('key1', 'value1');
map.set('key2', 'value2');
for (let [key, value] of map.entries()) {
console.log(key + ' - ' + value)
}
js loop trough map
for (let key of map) {
console.log(key);
}
use map to loop through an array
let squares = [1,2,3,4].map(function (val) {
return val * val;
});
// squares will be equal to [1, 4, 9, 16]
javascript Iterate Over Map Values
let map1 = new Map();
map1.set('name', 'Jack');
map1.set('age', '27');
// looping through the Map
for (let values of map1.values()) {
console.log(values);
}
how to loop through a map in js
var myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");
for (const [key, value] of Object.entries(myMap)) {
console.log(key, value);
}
Javascript using .map() loop to loop through an array
// Durations are in minutes
const tasks = [
{
'name' : 'Write for Envato Tuts+',
'duration' : 120
},
{
'name' : 'Work out',
'duration' : 60
},
{
'name' : 'Procrastinate on Duolingo',
'duration' : 240
}
];
const task_names = tasks.map(function (task, index, array) {
return task.name;
});
console.log(task_names) // [ 'Write for Envato Tuts+', 'Work out', 'Procrastinate on Duolingo' ]
map looping
showDetails(cards, id){
cards.map(function(card, index){
if(card.id==id){
console.log(card);
return card;
}
})
}
map loop
function findLongestWordLength(str) {
return Math.max(...str.split(" ").map(word => word.length))
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
© 2022 Copyright:
DekGenius.com