How to Remove Quotes from a String in TypeScript

You can remove quotes from a string in TypeScript with replaceAll('"', ""), which deletes every double quote. For single, double and curly quotes at once, use a global regex. When only the wrapping quotes should go, slice them off:

const clean = text.replaceAll('"', "");               // every double quote
const noQuotes = text.replace(/["'\u2018\u2019\u201C\u201D]/g, ""); // all quote types
const inner = text.slice(1, -1);                       // only if text starts and ends with a quote

My test machine had TypeScript 7.0.2 and Node.js v22.22.2, with --strict switched on, so the output under each block is what that setup actually printed.

Below you’ll find each method with its trap: the regex flag that throws, the compiler setting that hides replaceAll, smart quotes, and the JSON strings where a regex quietly breaks your data.

Remove all double quotes with replaceAll() or replace()

replaceAll() takes a plain string and swaps every match. The older replace() needs a regex with the g flag to do the same, because a string pattern only changes the first match:

const nickname: string = 'Chicago is "The Windy City" and "Chi-Town"';

console.log("replaceAll:", nickname.replaceAll('"', ""));
console.log("regex /g:  ", nickname.replace(/"/g, ""));
console.log("split/join:", nickname.split('"').join(""));
console.log("replace:   ", nickname.replace('"', ""));   // first quote only

try {
  nickname.replaceAll(/"/, "");                  // regex without the g flag
} catch (err) {
  console.log((err as Error).name + ":", (err as Error).message);
}

Output:

replaceAll: Chicago is The Windy City and Chi-Town
regex /g:   Chicago is The Windy City and Chi-Town
split/join: Chicago is The Windy City and Chi-Town
replace:    Chicago is The Windy City" and "Chi-Town"
TypeError: String.prototype.replaceAll called with a non-global RegExp argument
Command Prompt output of TypeScript removing quotes from a string with replaceAll, a global regex, split and join, and a TypeError for a non-global regex
Three ways remove every quote, replace() with a string stops after one, and a regex without g throws.

Notice the last line. Passing a regex to replaceAll() is fine, but it must carry the g flag or JavaScript throws a TypeError at runtime, and TypeScript won’t warn you at compile time.

The same methods work for any character, not just quotes; I cover the general case in replacing all occurrences of a substring in TypeScript.

Why does TypeScript say replaceAll does not exist?

If your tsconfig.json targets an older library, the compiler doesn’t know replaceAll() exists. Here’s the same code compiled with --lib es2020,dom:

const label: string = '"Austin, TX"';
const clean = label.replaceAll('"', "");
console.log(clean);

Output:

quotes_oldlib.ts(2,21): error TS2550: Property 'replaceAll' does not exist on type 'string'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later.
Command Prompt showing TypeScript error TS2550: Property replaceAll does not exist on type string, change the lib compiler option to es2021
TS2550 tells you exactly what to change: the lib option.

Set "lib": ["es2021"] or later (or a newer target) in tsconfig.json. If you can’t change the config, replace(/"/g, "") gives the same result and compiles everywhere.

Remove single, double and curly quotes from a string

Text pasted from Word, Google Docs or a CMS often has curly (smart) quotes, which a plain '"' won’t match. A character class catches every type in one pass:

const review: string = `She said "great food" and it's 'worth it': “5 stars”, ‘really’`;

const ALL_QUOTES = /["'`\u2018\u2019\u201C\u201D]/g;
const DOUBLE_QUOTES = /["\u201C\u201D]/g;

console.log("all quotes:   ", review.replace(ALL_QUOTES, ""));
console.log("double quotes:", review.replace(DOUBLE_QUOTES, ""));

Output:

all quotes:    She said great food and its worth it: 5 stars, really
double quotes: She said great food and it's 'worth it': 5 stars, ‘really’

Watch the apostrophe: removing every single quote turns it's into its. When the text has contractions or names like O’Brien, strip only double quotes, or remove just the wrapping pair as shown next.

Need to drop other symbols too? Add them to the class, or see removing a character from a string in TypeScript.

How do I remove only the surrounding quotes?

Often the quotes inside are real content, and only the outer pair is noise. This unquote() helper removes the first and last character only when they’re the same quote:

// Removes one matching pair of quotes from the start and end, nothing else.
function unquote(value: string): string {
  const match = value.match(/^(["'`])([\s\S]*)\1$/);
  return match ? match[2] : value;
}

const samples: string[] = [
  '"Austin"',
  "'Denver'",
  '"The "Big Apple""',
  'Say "hi" to Ana',
  '"Portland\'',
  '""',
  '"',
];

for (const s of samples) {
  console.log(s.padEnd(18), "->", `[${unquote(s)}]`);
}

Output:

"Austin"           -> [Austin]
'Denver'           -> [Denver]
"The "Big Apple""  -> [The "Big Apple"]
Say "hi" to Ana    -> [Say "hi" to Ana]
"Portland'         -> ["Portland']
""                 -> []
"                  -> ["]
Command Prompt output of a TypeScript unquote function that removes only the surrounding quotes from a string and keeps the inner quotes
The brackets mark where each result starts and ends: inner quotes survive, and mismatched pairs, plain text and a lone quote are left alone.

The \1 back-reference forces the closing quote to match the opening one, so "Portland' stays as it is. [\s\S]* also matches line breaks, which a plain . wouldn’t.

If you only ever deal with double quotes, a slice() with a check is easier to read:

function stripDoubleQuotes(value: string): string {
  return value.length >= 2 && value.startsWith('"') && value.endsWith('"')
    ? value.slice(1, -1)
    : value;
}

console.log(stripDoubleQuotes('"Miami, FL"'));
console.log(stripDoubleQuotes('Miami, FL'));

Output:

Miami, FL
Miami, FL

Skip the check and slice(1, -1) will happily chop real letters off unquoted text. More on trimming ends in removing the last character from a string in TypeScript.

Remove quotes from a JSON string with JSON.parse()

Here’s the case regex gets wrong. When a value went through JSON.stringify(), from an API, a cookie or localStorage, its quotes are part of the encoding and inner quotes are escaped:

// What an API or localStorage often hands you: a JSON-encoded string.
const raw = '"Ship to \\"Suite 400\\", Seattle, WA"';

console.log("raw:       ", raw);
console.log("replace:   ", raw.replace(/"/g, ""));
console.log("slice:     ", raw.slice(1, -1));

const parsed: unknown = JSON.parse(raw);
if (typeof parsed === "string") {
  console.log("JSON.parse:", parsed);
}

const stored = JSON.stringify("Boston, MA");
console.log(stored, "->", JSON.parse(stored));

Output:

raw:        "Ship to \"Suite 400\", Seattle, WA"
replace:    Ship to \Suite 400\, Seattle, WA
slice:      Ship to \"Suite 400\", Seattle, WA
JSON.parse: Ship to "Suite 400", Seattle, WA
"Boston, MA" -> Boston, MA
Command Prompt output comparing replace, slice and JSON.parse for removing quotes from a JSON-encoded string in TypeScript
Only JSON.parse() returns the original text; replace and slice leave stray backslashes.

JSON.parse() returns any, so I store it as unknown and check typeof before using it. That keeps strict mode honest if the payload turns out not to be a string.

For typed objects instead of single strings, read converting JSON to a TypeScript interface, and importing a JSON file in TypeScript for files on disk.

Remove quotes from every string in an array or CSV row

Because unquote() takes one string and returns one, you can pass it straight to map(). Here it cleans a simple CSV row from a Denver store export and a list of tags:

function unquote(value: string): string {
  const match = value.match(/^(["'`])([\s\S]*)\1$/);
  return match ? match[2] : value;
}

const row = '"Denver","CO","1249.5"';
const [city, state, price] = row.split(",").map(unquote);
console.log({ city, state, price: `$${Number(price).toFixed(2)}` });

const tags: string[] = ['"sale"', "'new'", "clearance"];
console.log(tags.map(unquote));

Output:

{ city: 'Denver', state: 'CO', price: '$1249.50' }
[ 'sale', 'new', 'clearance' ]

A plain split(",") breaks when a quoted field contains a comma, like "Austin, TX", so use a CSV parser for real files. More on splitting in converting a string to an array in TypeScript.

Escape double quotes instead of removing them

Sometimes you don’t want the quotes gone, you just need them inside a string literal. Escape them with a backslash, switch the outer quote style, or use a template literal:

const a: string = "She said \"yes\"";
const b: string = 'She said "yes"';
const c: string = `She said "yes" and it's final`;

console.log(a === b);
console.log(c);
console.log(JSON.stringify({ quote: b }));

Output:

true
She said "yes" and it's final
{"quote":"She said \"yes\""}

All three hold the same text, so a === b is true. JSON.stringify() adds the escaping for you when you send data out. Template literals also help with multiline strings in TypeScript.

Ways to remove quotes from a string in TypeScript compared

GoalUseWatch out for
Every double quotes.replaceAll('"', "")Needs lib es2021 or later
Every quote types.replace(/["'\u2018\u2019\u201C\u201D]/g, "")Also removes apostrophes
Only the wrapping pairunquote() or a checked slice(1, -1)Check both ends first
A JSON-encoded valueJSON.parse() + typeof checkThrows on invalid JSON
A whole arrayarr.map(unquote)Commas inside quoted CSV fields

Working with more string tasks? These guides pick up where this one stops:

Frequently asked questions

How do I remove all double quotes from a string in TypeScript?

Call text.replaceAll('"', ""), or text.replace(/"/g, "") if your lib setting is older than ES2021.

How do I remove only the first and last quote?

Check that the string starts and ends with the same quote, then use slice(1, -1). The regex /^(["'])([\s\S]*)\1$/ does both in one step.

Why does replaceAll throw a TypeError with a regex?

replaceAll() requires a global regex. Add the g flag, as in /"/g, or pass a plain string instead.

Why does my string still show quotes after JSON.stringify?

JSON.stringify() wraps strings in quotes on purpose. Use JSON.parse() to get the plain text back instead of stripping them by hand.

How do I remove curly or smart quotes?

Include their Unicode escapes in a character class: /[\u2018\u2019\u201C\u201D]/g, then replace with an empty string.

Where is replaceAll documented?