Languages
[Edit]
EN

JavaScript - remove first 3 characters from string

9 points
Created by:
Aleena
694

In JavaScript it is possible to remove first 3 characters from string in following ways.

1. Using String slice() method

Edit

In second example we can see that we can also use string slice on empty or shorter string then 3 characters (or in case if we want to remove n characters from our string).

We use ''.slice(3) === '' to see that the string after slice operation is empty.

Empty result means that string was shorter then 3 characters or the length was exactly 3 characters and our string is empty (the length of the string is 0).

Because string slice returns string then we can also call string length method to check the size of returned string, like on below example:

2. Using String substring() method

Edit

3. Using String replace() method

Edit

Merged questions

Edit
  1. JavaScript - how to chop off first 3 chars from string?
  2. How do I trim off first 3 characters in JavaScript?
  3. JavaScript - delete first 3 chars of string
  4. Slice off first 3 characters in js
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - remove first 3 characters from string

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join