![]() |
VOOZH | about |
To delete the first character of a string in JavaScript, you can use several methods. Here are some of the most common ones
The slice() method is frequently used to remove the first character by returning a new string from index 1 to the end.
Output
eeksforGeeksSimilar to slice(), substring() creates a new string starting from index 1, effectively removing the first character.
Output
eeksforGeeksConvert the string into an array of characters, remove the first character, and join it back into a string.
Output
eeksforGeeksThe replace() method removes the first character using a regular expression that matches the first character (^.).
Output
eeksforGeeksNote: In most cases, slice() and substring() are preferred for their simplicity and readability.