title: string.match() returns a String instead of an Array
body: <p>I've been using Javascript <code>string.match(*regex*)</code> function to parse the <code>navigator.userAgent</code> string.</p>
  
  <p>FYI, According to MDN &amp; W3schools: </p>
  
  <blockquote>
    <p>"The match() method searches a string for a match against a regular expression, and returns the matches, as an <strong>Array object</strong>."</p>
  </blockquote>
  
  <p>I first parse once to get the wanted strings for the base string:</p>
  
  <pre><code>var userAgent = navigator.userAgent;
  var splitted = userAgent.match(/[(][^)]+[)]|\w+\/\S+/ig);
  </code></pre>
  
  <p>Which gives me the following Output (Which is an Array)</p>
  
  <pre><code>Mozilla/5.0
  (Macintosh; Intel Mac OS X 10_10_3)
  AppleWebKit/537.36
  (KHTML, like Gecko)
  Chrome/41.0.2272.76
  Safari/537.36
  </code></pre>
  
  <p>Then i parse the <em>Navigator/Version</em> type strings in a for loop</p>
  
  <pre><code>for (var i = 0; i &lt; splitted.length; i++ ) {
      var str = splitted[i];
      if (str[0] == '(') {
      } else {
          var name = str.match(/[^\/]+/i);
          var version = str.match(/[0-9|\.]+/i);
  }
  </code></pre>
  
  <p>But, very surprisingly and even though I get the desired result, <strong>I get a String Object for the <em>name</em> and an Array Object for the <em>version</em></strong></p>
  
  <p>How is it even possible ?</p>
  
  <p>Here's the snippet of the code (<a href="https://jsfiddle.net/baxnLyhL/1/" rel="nofollow">fiddle</a>):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var userAgent = navigator.userAgent;
  var splitted = userAgent.match(/[(][^)]+[)]|\w+\/\S+/ig);
  var outputDiv = document.getElementById("log");
  
  for (var i = 0; i &lt; splitted.length; i++ ) {
    var str = splitted[i];
    if (str[0] == '(') {
    } else {
      var name = str.match(/[^\/]+/i);
      var version = str.match(/[0-9|\.]+/i);
      outputDiv.innerHTML += name.toString() + " is a " + typeof(name) + "&lt;br&gt;";
      outputDiv.innerHTML += version.toString() + " is a " + typeof(version) + "&lt;br&gt;";
    }
  };</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="log"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>--- UPDATE ---</p>
  
  <p>Thanks <strong>FactoryAidan</strong> for the answer, it was a scope problem.</p>
  
  <p><strong>Conclusion: be careful when naming global variables :)</strong></p>