title: Pick the other element in a Javascript array containing two
body: <p>I have a javascript array like:</p>
  
  <pre><code>var arr = ['black', 'white'];
  </code></pre>
  
  <p>Now if I have a variable containing one of the element, how can I easily get the other? For example</p>
  
  <pre><code>var color = 'black';
  var otherColor = '???'; // should be 'white', how can I get it?
  </code></pre>
  
  <p>I'm looking for the simplest/cleaner way possible.</p>
  
  <p>Also, I don't want to mutate the original array.</p>
  
  <p>Thanks</p>
  
  <p><strong>ANSWER</strong></p>
  
  <p>What about:</p>
  
  <pre><code>var otherColor = arr[1 - arr.indexOf(color)]
  </code></pre>