Javascript remove first character from string example; In this tutorial how to remove the first character from a string in JavaScript.
In javascript we can remove the first character from a string three ways:
1. Using slice() method
The slice() method extracts the text from a string and returns a new string.
const str = 'coding driver';
const withoutFirst = str.slice(1);
console.log(withoutFirst); // oding driver
2. Using substring() method
The substring() method returns the part of the string between the specified indexes or to the end of the string.
const str = 'coding driver';
const withoutFirst = str.substring(1);
console.log(withoutFirst); // oding driver
3. Using substr() method
The substr() method returns a portion of the string, starting at the specified index and extending for a given number of characters or until the string’s end.
const str = 'coding driver';
const withoutFirst = str.substr(1);
console.log(withoutFirst); // oding driver