title: Find all the combinations of a string Javascript
body: <p>I want to find all the combinations of a string in javascript. I looked up previously asked questions but there is one output missing and I don't know how to find it.</p>
  
  <p><strong>My code is:</strong></p>
  
  <pre><code>    &lt;html&gt;
      &lt;head&gt;&lt;/head&gt;
      &lt;body&gt;
      &lt;label&gt;Enter word/sentence to generate combinations:&lt;/label&gt;
          &lt;input type="text" name="comb"/&gt;&lt;/br&gt;
          &lt;input type="button" value="Get Combination" name="combbtn" onclick="substrings()"/&gt;
          &lt;script&gt;
              function substrings(){
                  var str=document.getElementsByTagName("input")[0].value;
                  var i, j, result = [];
                    for (i = 0; i &lt; str.length; i++) {
                        for (j = i + 1; j &lt; str.length + 1; j++) {
                            result.push(str.slice(i, j));
                        }
                    }
                    alert(result);
              }
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I try "dad" as input, the expected output is:-</p>
  
  <blockquote>
    <p>d,a,da,d,dd,ad,dad</p>
  </blockquote>
  
  <p>But my code somehow misses </p>
  
  <blockquote>
    <p>"dd"</p>
  </blockquote>
  
  <p>How can I include it. Any help/suggestion?</p>