In JavaScript, to remove quotes from a string the easiest way is to use the JavaScript String replace() method. You can remove single and double quotes using replace().

var singleQuoteString = "This' is' a' string' with' quotes."
var doubleQuoteString = 'This" is" a" string" with" quotes.'

singleQuoteString = singleQuoteString.replace(/'/g, '');
doubleQuoteString = doubleQuoteString.replace(/"/g, '');

console.log(string_without_single);
console.log(string_without_double);

#Output:
This is a string with quotes.
This is a string with quotes.

Notice in the replace method above, that instead of using .replace("'", '') we use replace(/'/g, ''). If we used the expression "'" in the replace function, it only replaces the FIRST instance of a single quote. Using the regular expression /'/g makes it so we replace ALL instances of a single quote in the string.


When using string variables in JavaScript, we can easily perform string manipulation to change the value of the string variables.

One such manipulation is to remove characters from a string variable. Quotes, both single and double quotes, can be troubling characters to deal with in string variables.

We can easily remove quotes from a string in JavaScript.

The easiest way to get rid of both single and double quotes in a string using JavaScript is with the JavaScript String replace() function.

The replace() function takes two arguments: the substring we want to replace, and the replacement substring. In this case, to remove quotes, we pass the single (“‘”) or double (‘”‘) quote character as the first argument, and an empty string as the second argument.

Below are some examples of how you can remove quotes from strings in JavaScript using the replace() function.

var singleQuoteString = "This' is' a' string' with' quotes."
var doubleQuoteString = 'This" is" a" string" with" quotes.'

singleQuoteString = singleQuoteString.replace(/'/g, '');
doubleQuoteString = doubleQuoteString.replace(/"/g, '');

console.log(string_without_single);
console.log(string_without_double);

#Output:
This is a string with quotes.
This is a string with quotes.

Hopefully this article has been useful for you to learn how to in JavaScript remove quotes from string.

Categorized in:

JavaScript,

Last Update: February 26, 2024