There are three methods in JavaScript to get a substring.
  • str.slice(start, end) returns the part of the string from start but not including the end. 
let fullname = 'Akshay Khot';
let firstname = fullname.slice(0, 6); // Akshay
        The second parameter is optional, in which case it returns the              substring from start till the end.
let fullname = 'Akshay Khot';
let lastname = fullname.slice(7); // Khot
  • str.substring(start, end) is same as slice, but allows the start to be greater than end. 
let fullname = 'Akshay Khot';
let firstname = fullname.substring(6, 0); // Akshay
  • str.substr(start, length) returns the part of the string from start, with the given length. The second parameter is optional, similar to slice. Exists for historical reasons. 
let fullname = 'Akshay Khot';
let lastname = fullname.substr(7, 4); // Khot
If you just want to remember one, use slice.