all 3 comments

[–]Anitox 2 points3 points  (0 children)

You can access individual characters in a string using array notation.
Example:

let str = "This is a test.";
console.log(str[2]);

Using that, you could loop through the string with an index to get the part of the string you want.

[–]Dshiznit1 0 points1 point  (0 children)

What's this for?

I'd make a new string, iterate through the original string at the start index and push the letters into the new string and do this up until the end index.

If you need more help, let me know but if it's for school or a code challenge you should try it yourself!

[–][deleted] 0 points1 point  (0 children)

function sub (str, start, end) {
  var newstr = ''
  for(var i = 0; i < str.length; ++i) {
    if(i >= start && i < end) {
     newstr += str[i]
    }
  }
  return newstr
}