title: Discord.js How to manipulate variables to make the text output display after array variables change
body: <pre><code>var Playe0;
  var loca = ['L0', 'R0', 'L1', 'R1', 'L2', 'R2', 'L3', 'R3'];
  var dead = [0, 0, 0, 0, 0, 0, 0, 0]; 
  
  bot.on("message", function (msg) {
      var alive = dead.map((v, i) =&gt; !v ? loca[i] : null).filter(v =&gt; v != null); 
      if (msg.content === "!p0") { Player0 = msg.author.id; msg.channel.send(`Registered`); }
      if (msg.author.id === Player0) {
          if (msg.content === "k") { 
              dead[0] = 1; 
              msg.channel.send(`Targets: ` + alive.join(", ")); }
      }
  </code></pre>
  
  <p>This code eventually does what I need, but the proccess in which it does it is incorrect.<br>
  It's supposed to change the first index of the dead array to a 1 or 0 and then send the message.
  Currently, it sends the message and then changes the value. Outside of jargon it doesn't remove the value from the output like it should. </p>
  
  <p>L0 User Input for Desired Output: <code>k</code></p>
  
  <p>Current Output: <code>Targets: L0, R0, L1, R1, L2, R2, L3, R3</code><br>
  Desired Output: <code>Tagets: R0, L1, R1, L2, R2, L3, R3</code>    </p>
  
  <p>I've removed the extra players for now as I can distribute the changes.<br>
  If the user associated with R0 inputs <code>k</code> afterwards then the output is <code>R0, L1, R1, L2, R2, L3, R3</code><br>
  This shows that the code is changing the index, but it is sending the message before the change is registered. This is probably due to the placement or use of the alive variable. </p>