title: How can I return a value within a javascript Map?
body: <p>I have a JS function running in Node Red and I am trying to run a loop against the values in the map. How can I reference EventID and ProgramName in the loop below? Or should they not be assigned a variable name?</p>
  <pre><code>msg.out1ID = 0;
  msg.out2ID = 0;
  msg.out3ID = 0; 
  msg.availabletowrite = true;
  
  
  const Events = new Map([
      [EventID = msg.payload.EventID1,  ProgramName = msg.payload.program1],
      [EventID = msg.payload.EventID2,  ProgramName = msg.payload.program2],
      [EventID = msg.payload.EventID3,  ProgramName = msg.payload.program3],
  ]);
  flow.set(&quot;Events&quot;, Events);
  for (var x in Events){
      if (msg.out1ID == EventID || msg.out2ID == EventID || msg.out3ID == EventID) {
          msg.availabletowrite = false
          msg.loop += 1;
      }
      if (msg.availabletowrite) {
          if (ProgramName == &quot;PRD&quot;) {
              if (msg.out1ID == 0) {
                  msg.out1 = 1; //Dispatch msg.output 1
                  msg.out1ID = EventID;
                  msg.loop += 10;
                  msg.loop1 = true;
                  // continue;
              }
          }
  
          if (ProgramName == &quot;DD&quot;) {
              if (msg.out2ID == 0) {
                  msg.out2 = 1; //Dispatch msg.output 1
                  msg.out2ID = EventID;
                  msg.loop += 100;
                  // continue;
              }
          }
          //If it gets here we need a third. Don't bind to program specific
          if (msg.out3ID == 0) {
              msg.out3 = 1; //Dispatch msg.output 1
              msg.out3ID = EventID;
              msg.loop += 1000;
              // continue;
          }
      }
  }
  return msg;
  
       
  </code></pre>