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);
}
iterate map
Map<String, String> map = ...
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey() + "/" + entry.getValue());
}
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);
}
iteratea on values map js
map.values((value) => /* do whatever with 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' ]
iterate map
for (let [key, value] of map.entries()) {
console.log(key, value);
}
Iterating through a map
for (auto const& [key, value] : your_map) {
std::cout << key << ':' << value << std::endl;
}
iterating map javascript
map.forEach(function(value, key) {
console.log(key + ' = ' + value);
})
javascript loop through array using .map
const loadAll = async function (imgArr) {
try {
let singleImage = imgArrItem => createImage(imgArrItem);
// creates 3 promises
const imgs = imgArr.map(singleImage);
console.log(imgs);
} catch (error) {
console.log('Images not loaded');
}
};
loadAll(['img/img-1.jpg', 'img/img-2.jpg', 'img/img-3.jpg']);
© 2022 Copyright:
DekGenius.com