title: Find Unique Number from array in JavaScript
body: <p><strong>Please let me know is this a best approach to find unique number from an array?</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var singleNumber = function(nums) {
    for (var i = 0; i &lt; nums.length; i++) {
      if (i === 0) {
        nums[0] = 0 ^ nums[0];
        /* console.log(nums[0]); */
      } else {
        nums[0] ^= nums[i];
        /* console.log(nums[0]); */
      }
  
    }
    console.log(nums[0]);
    return nums[0];
  
  
  };
  
  singleNumber([2, 2, 3, 3, 4]);</code></pre>
  </div>
  </div>
  </p>
  
  <p><em>If you have any better approach with this, help me out.</em></p>