Program to print all substrings of a given string | Function to print all ( n * ( n + 1 ) ) / 2 subStrings of a given String s of length n . ; Fix start index in outer loop . Reveal new character in inner loop till end of String . Print till - now - formed String . ; Driver code
function printAllSubStrings ( s , n ) { for ( let i = 0 ; i < n ; i ++ ) { let temp = new Array ( n - i + 1 ) ; let tempindex = 0 ; for ( let j = i ; j < n ; j ++ ) { temp [ tempindex ++ ] = s [ j ] ; temp [ tempindex ] = ' \0 ' ; document . write ( temp . join ( " " ) + " " ) ; } } } let s = " " ; printAllSubStrings ( s , s . length ) ;