How to Remove First Character from String in JavaScript

Here are three ways to remove the first character from a string in JavaScript:

  1. Using slice()
  2. Using substring()
  3. Using replace()

Method 1: Using slice()

The string.slice() method extracts a part of a string. It does not change the original string.

We can slice the first character from the string using the slice() method.

Here is a code example:

let string = "Greetings from JavaScript";
string = string.slice(1)
console.log(string);

Output

reetings from JavaScript

Method 2: Using substring()

let string = "Greetings from Javascript";
string = string.substring(1)
console.log(string);

Output

reetings from Javascript

Using the substring() method, we removed the first character “G” from the string using the substring() method.

Don’t use the “substr()” method to remove the first character from a string in JavaScript because it is deprecated and won’t be available in the future. You can learn more about this on Mozilla docs.

Method 3: Using the replace() method

The String.replace() method is used to search a string for a value or a regular expression. It only replaces the first occurrence of the matched string.

let string = "Greetings from Javascript";
let firstChar = string.charAt(0);
const newString = string.replace(firstChar, '');
console.log(newString)

Output

reetings from Javascript

Conclusion

The most efficient way to remove the first character from a string in JavaScript is to use the string.slice() method.

Related posts

How to Get Last Character from String in Javascript

How to Get First Character of String in JavaScript

How to Get Character from String in JavaScript