How to iterate over javascript Map without forEach (so I could break in the middle, or is there a way to break from forEach? Couldn't use object since the order is sometimes random on certain browser, where Map ordering is as defined.
let map = new Map();
map.set(1,'google.com');
// very long list
map.set(12312,/[^a-z]+/);
let match = 'nothing';
for(let z in map) { // doesn't work, but works for object
if( foo.match(z) ) {
match = map.get(z); // map[z]; on object
break;
}
}
the nearest thing i found is using .keys()
let iter = map.keys();
while(!iter.next().done) {
if(foo.match(iter.value)) {
match = map.get(iter.value);
break
}
}