Skip to content
the poor coder

remove first 3 characters from string javascript

Poor Man
Published
Reading time
1 min read
On this page

How to Remove First 3 Characters from a String in JavaScript#

If you have a string in JavaScript and you want to remove the first 3 characters from it, there are several ways to do it. Here are a few:

Method 1: Using the slice() Method#

The slice() method returns a portion of a string, starting at the specified index and extending for a given number of characters. To remove the first 3 characters, you can use the slice() method like this:

Text

let str = "Hello World";
let newStr = str.slice(3);
console.log(newStr); // Output: "lo World"

Method 2: Using the substring() Method#

The substring() method returns the part of the string between the start and end indexes, or to the end of the string. To remove the first 3 characters, you can use the substring() method like this:

Text

let str = "Hello World";
let newStr = str.substring(3);
console.log(newStr); // Output: "lo World"

Method 3: Using the substr() Method#

The substr() method returns a specified part of a string, starting from a specified index and including the specified number of characters. To remove the first 3 characters, you can use the substr() method like this:

Text

let str = "Hello World";
let newStr = str.substr(3);
console.log(newStr); // Output: "lo World"

These are three ways to remove the first 3 characters from a string in JavaScript. Choose the one that works best for your specific use case.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC