Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove First Character of (Original) String in JavaScript [duplicate]

Tags:

javascript

I see this article but it's specific to deleting a character if it's a certain number (0, in that case).

I want to remove the first character from a string no matter what it is.

splice() and shift() won't work because they're specific to arrays:

let string = "stake";
string.splice(0, 1);
console.log(string);

let string = "stake";
string.shift();
console.log(string);

slice() gets the first character but it doesn't remove it from the original string.

let string = "stake";
string.slice(0, 2);
console.log(string);

Is there any other method out there that will remove the first element from a string?

like image 868
HappyHands31 Avatar asked Dec 18 '22 17:12

HappyHands31


1 Answers

Use substring

let str = "stake";
str = str.substring(1);
console.log(str);
like image 89
abney317 Avatar answered Apr 08 '23 11:04

abney317