

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Removing a specific substring from a string in JavaScript
<p>We are given a main string and a substring, our job is to create a function, let’s say removeString() that takes in these two arguments and returns a version of the main string which is free of the substring.</p><p>Here, we need to remove the separator from a string, for example −</p><pre class="result notranslate">this-is-a-sting</pre><p>Let’s now write the code for this function −</p><pre class="prettyprint notranslate">const removeString = (string, separator) => { //we split the string and make it free of separator const separatedArray = string.split(separator); //we join the separatedArray with empty string const separatedString = separatedArray.join(""); return separatedString; } const str = removeString('this-is-a-sting', '-'); console.log(str);</pre><p>The output of this code in the console will be −</p><pre class="result notranslate">thisisastring</pre>
- Related Questions & Answers
- Removing punctuations from a string using JavaScript
- Removing adjacent duplicates from a string in JavaScript
- Removing all spaces from a string using JavaScript
- Removing all non-alphabetic characters from a string in JavaScript
- Removing n characters from a string in alphabetical order in JavaScript
- Removing first k characters from string in JavaScript
- Removing comments from array of string in JavaScript
- Removing property from a JSON object in JavaScript
- Removing nth character from a string in Python program
- How to find a substring from a string in C#?
- Python program for removing nth character from a string
- How can we extract a substring from a string in MySQL?
- How to extract a substring from inside a string in Python?
- How to check whether a string contains a substring in JavaScript?
- How can we get substring from a string in Python?
Advertisements