How to remove part of a string?

Viewed 256165

Let’s say I have test_23 and I want to remove test_.

How do I do that?

The prefix before _ can change.

6 Answers

If you want to remove part of string

let str = "try_me";
str.replace("try_", "");
// me

If you want to replace part of string

let str = "try_me";
str.replace("try_", "test_");
// test_me

let text = 'test_23';
console.log(text.substring(text.indexOf('_') + 1));

Related