Find indices of all occurrence of one string in other | JavaScript program to find indices of all occurrences of one String in other . ; Driver code
function printIndex ( str , s ) { var flag = false ; for ( var i = 0 ; i < str . length - s . length + 1 ; i ++ ) { if ( str . substring ( i , s . length + i ) == s ) { document . write ( i + " " ) ; flag = true ; } } if ( flag === false ) { document . write ( " " ) ; } } var str1 = " " ; var str2 = " " ; printIndex ( str1 , str2 ) ;