Map & iterator

by Gerald Gillespie

JavaScript

const myMap = new Map(); 
let i; 

myMap.set('entry1','value1');
myMap.set('entry2','value2');


function iterateMap(message, map){
  console.log(`${message} to iterateMap`)
 
	for( let [key,value] of map){
  	if(i<0)
    	continue;
  	console.log(`loop ${i}`,key,value);
    --i;
  	iterateMap('inside', map); 
    //this will never be reached
    console.log('this would never be reached until loop is broken');
  }
}

i=10;
console.log('******** A: THIS WILL LOOP TO THE MAX')
iterateMap('outside',[...myMap.entries()])


i=10;
console.log('********B:  THIS WILL LOOP 1 ITERATION THROUGH THE each entry')
iterateMap('outside',myMap.entries())


i=10;
console.log('******** C: THIS WILL LOOP TO THE MAX')
iterateMap('outside','AB')

i=10
console.log('******** D: THIS WILL LOOP TO THE MAX')
iterateMap('outside',myMap);

i=10
console.log('******** E: THIS WILL LOOP 1 ITERATION THROUG each entry')
iterateMap('outside', 'AB'[Symbol.iterator]())


i=10
console.log('******** F: THIS WILL LOOP 1 ITERATION THROUG each entry')
iterateMap('outside', ['A','B'][Symbol.iterator]())