1

I have a string btnHome. How can I remove btn and only get Home from it in javascript / jQuery?

I used slice like str.slice(3, -1) but it gives me Hom whereas I need Home.

5 Answers 5

1

Remove the -1 part (just use str.slice(3)).

The -1 argument says slice to 1 character from the end of the string.

Sign up to request clarification or add additional context in comments.

Comments

0

Try like

alert(str.slice(3));

Need not to give -1 there.So it will slice it from starting of the string.

Comments

0

You should use substr() method:

  target.substr(3);

Comments

0

Demo

  var txt="btnHome";
  txt.slice(3,txt.length)

By using substring

 txt.substring(3,txt.length);

Comments

0

Two simple ways to do it:

str.split('btn')[1]; // Home

str.slice(3); // Home

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.