title: iterating a string with results formmated into an object inJS
body: <p>I have a function which produces the result of a string into an object with  the letters counted as values of the properties in a key/value format.</p>
  
  <pre><code>var output = countAllCharsIntoObject('banana');
  console.log(output); // --&gt; {b: 1, a: 3, n: 2}
  </code></pre>
  
  <p>My issue is that beside the looping of an array of the string </p>
  
  <pre><code>function countAllCharsIntoObject(str){
      var arr = str.split('');
      var obj = {};
      for(var i = 0; i &lt; arr.length; i++) {
          //how to iterate the arr[i] and assign the value of the chars to the       
          //keys/values of the new obj. And if more then 1 indexOf(arr[i]) then   
          //change through an iteration the value of the new char key.I tried so   
          //many solutions without effect.
      }
      return obj;
  }
  </code></pre>
  
  <p>Just can not wrap my mind around the fact that i simultaneously loop within a loop with assignment to key/values of the results of the loop (with dynamic increment of values).
  Any help would be appreciated!
  Just in plain JS please... no underscore or lodash or jQuery solutions. 
  Thanks!</p>