Skip to content
Advertisement

Get all substrings of a string in JavaScript

I have the following function to get all of the substrings from a string in JavaScript. I know it’s not correct but I feel like I am going about it the right way. Any advice would be great.

JavaScript

Edit: Apologies if my question is unclear. By substring I mean all combinations of letters from the string (do not have to be actual words) So if the string was ‘abc’ you could have [a, ab, abc, b, ba, bac etc…] Thank you for all the responses.

Advertisement

Answer

You need two nested loop for the sub strings.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement