6 Ultimate Solutions to Remove Character from String in JavaScript

Today, we are going to show you different ways to remove characters from a string in JavaScript.

You’ll learn six different methods to remove characters from strings.

Each method is explained with code examples and outputs.

This article also covers how to remove the last character or a specific character from a string.

Let’s dive in to enhance your JavaScript skills.

How to remove characters from string in JavaScript?

The following are six different ways to remove characters from a string in JavaScript:

Solution 1: Use the replace() method

The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.

Here’s an example:

let sampleString = "Hi, Welcome to Itsourcecode!";
let newSampleString = sampleString.replace("H", ""); ✅
console.log(newSampleString);

Output:

 i, Welcome to Itsourcecode!

The character “H,” has been removed.

Solution 2: Use the slice() method

The slice() method extracts parts of a string and returns the extracted parts in a new string.

Here’s an example:

let sampleString = "Itsourcecode!";
let newSampleString = sampleString.slice(0, 8); ✅
console.log(newSampleString);

Output:

Itsource

Solution 3: Use the substring() method

The substring() method extracts the characters from a string, between two specified indices, and returns the new sub string.

Here’s an example:

let sampleString = "Hi Welcome to Itsourcecode!";
let newSampleString =  sampleString.substring(3, 10); ✅
console.log(newSampleString)

Output:

Welcome

Solution 4: Use the split() and join() methods

The split() method is used to split a string into an array of substrings, and returns the new array. The join() method joins all elements of an array into a string.

Here’s an example:

let sampleString = "Hi Welcome to Itsourcecode!";
let newSampleString = sampleString.split('Hi').join(''); ✅
console.log(newSampleString)

Output:

 Welcome to Itsourcecode!

Solution 5: Regular Expressions with the replace() method

Regular expressions can be used with the replace() method to find patterns within strings.

Here’s an example:

let sampleString = "Hi Welcome to Itsourcecode!";
let newSampleString = sampleString.replace(/Hi Welcome to/g, ''); ✅
console.log(newSampleString)

Output:

 Itsourcecode!

Solution 6: Use the substr() method

The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.

Here’s an example:

let sampleString = "Hi Welcome to Itsourcecode!";
let newSampleString = sampleString.substr(0, 10); ✅
console.log(newSampleString)

Output:

Hi Welcome

📌Please note that these methods do not modify the original string but return a new one.

The original string remains unchanged. Also remember that JavaScript strings are case sensitive.

How to remove last character from string in JavaScript?

To remove the last character from a string in JavaScript by using the slice() method.

As we mentioned above, slice() method extracts a part of a string and returns the extracted part in a new string.

Here’s an example:

let sampleString = "Hi Welcome to Itsourcecode";
let newSampleString = sampleString.slice(0, -1); 
console.log(newSampleString)

In our example code, slice(0, -1) extracts from the start of the string (index 0) to the end of the string, excluding the last character (because of -1).

The result is a new string with the last character removed.

Output:

Hi Welcome to Itsourcecod

As you can see, the character “e” in the last string is already removed.

How to remove a specific character from a string in JavaScript?

To remove a specific character from a string, you can use the replace() method in JavaScript.

As we mentioned earlier, the replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.

Here’s an example of how to remove the character “e” from a string:

let sampleString = "Hi Welcome to Itsourcecode!";
let newSampleString = sampleString.replace(/e/g, '');  ✅
console.log(newSampleString)

As you can see in our example, /e/g is a regular expression that matches the character “e” in the string, and “g” is a flag that indicates a global search for all ‘e’ in the string.

The replace() method replaces each “e” with an empty string (“”), effectively removing all “e” from the string.

Conclusion

In conclusion, manipulating strings is a common task in JavaScript, and understanding how is an essential skill.

In this article, we explored six different methods to effectively remove characters from a string including replace(), slice(), substring(), split(), and join(), regular expressions with replace(), and substr().

Each method was demonstrated with practical examples and their outputs. 

We also covered how to remove the last character or a specific character from a string.

We hope this article has provided you with enough information to understand the JavaScript remove character from string.

If you want to explore more JavaScript topics, check out the following articles:

Thank you for reading Itsourcecoders 😊.

Frequently Asked Questions

Is JavaScript still worth learning in 2026?
Yes. JavaScript runs on 98% of websites for the front-end, dominates the back-end via Node.js, powers mobile apps through React Native, builds desktop tools through Electron, and is the scripting layer for most AI tooling (LangChain.js, OpenAI SDK, Vercel AI). Whether you target web, mobile, AI, or full-stack capstones, JavaScript is the broadest single language you can learn.
What is the difference between var, let, and const?
var is function-scoped, hoisted to the top of its scope, and can be redeclared, which leads to bugs in modern code. let is block-scoped (only visible inside the nearest {}) and can be reassigned. const is block-scoped and cannot be reassigned, although object contents can still mutate. Default to const for everything, switch to let only when you actually need to reassign, and avoid var in any code written after 2017.
Which JavaScript version should I target in 2026?
Target ES2020 (ES11) as the safe baseline because every modern browser and Node.js 14+ supports it fully. ES2022 adds useful features like top-level await, private class fields with the # prefix, and the .at() array method. If you are writing for older browsers (IE11 or older Android WebViews), transpile down with Babel or use a build tool like Vite, esbuild, or webpack.
What is the best free editor for JavaScript?
Visual Studio Code is the industry standard, free, with built-in IntelliSense, debugger, terminal, Git, and a huge extension marketplace (ESLint, Prettier, GitHub Copilot, Tailwind). Install the JavaScript and TypeScript Nightly extension for the latest language features. JetBrains WebStorm is more powerful and free for students with a verified .edu email. For quick scratchpad work, the Chrome DevTools Sources panel includes a workspace and breakpoint debugger.
How do I run JavaScript locally vs in the browser?
In the browser: open DevTools with F12 (or right-click then Inspect), go to the Console tab, type or paste your code, press Enter. For HTML pages, add a script tag pointing to your .js file. Locally with Node.js: download Node from nodejs.org (LTS version), then run node script.js in your terminal from the file folder. Use the same Node setup for backend capstones, API integrations, and scripts that do not need a browser.
What can I build with JavaScript for my BSIT capstone?
Common BSIT capstones in JavaScript: full-stack web apps using React or Vue on the front-end with Node.js and Express on the back-end (MongoDB or MySQL for the database), real-time chat or notification systems using Socket.io, single-page dashboards with Chart.js or D3.js, cross-platform mobile apps with React Native, AI-powered chatbots using OpenAI SDK and LangChain.js, and Chrome extensions for productivity tools. Add Tailwind CSS for the UI and Vercel or Netlify for free deployment.

Leave a Comment