title: if JavaScript string starts with hyphen then count occurrences
body: <p>Basically I have an array of strings like this:</p>
  
  <pre><code>var array = [
      'Top level',
      '- Sub item',
      '-- Child of sub',
      'Another top',
      'Yet another top',
      '- Child',
  ];
  </code></pre>
  
  <p>I'm trying to loop each string and check if the string starts with a hyphen, if so count how many times and then remove.</p>
  
  <p>I can do it kind of like this:</p>
  
  <pre><code>if (string.substring(0, 1) == "-") {
      // ...
  } else if (string.substring(0, 2) == "--") {
      // ...
  } else if (string.substring(0, 3) == "---") {
      // ...
  }
  </code></pre>
  
  <p>I haven't tested but you can get the idea..</p>
  
  <p>I'm hoping for an easier solution maybe with a regex? Any help?</p>
  
  <p>Thanks.</p>
  
  <p><strong>-- EDIT --</strong></p>
  
  <p>I need to count and remove the hyphens from each string because I have a text area for a user to enter a string with new lines and hyphens.</p>
  
  <p>Textarea value:</p>
  
  <pre><code>Top level
  - Sub item
  -- Child of sub
  Another top
  Yet another top
  - Child
  </code></pre>
  
  <p>I am then exploding the textarea value into an array:</p>
  
  <pre><code>var array = textareaValue.split('\n');
  
  for (var i = 0; i &lt; array.length; i++) {
      var this = array[i];
      // Now check for hyphens and count how many
      // if (hyphens === '-')
      // else if (hyphens === '--') ...etc
  };
  </code></pre>