Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
How to replace or encode single and right double quotation mark in JavaScript?

I have string contains this “No.” as you see that's not normal double quotes. I tried to encode it manually by using replace like this

var stmt = "select “No.”";
stmt = stmt.replace('“', '\u201c');
stmt = stmt.replace('”', '\u201d');

console.log(stmt);

But when I log stmt I find that nothing changed at all and logs this “No.”. How can I encode such special characters in Javascript? I'm using sequelize to insert this statement to the database and need it to be encoded to be displayed correctly inside a JSON string so the final result should be \u201cNo.\u201d

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You need to use the escape character \ to prevent JS to interpret "\u201c" and "\u201d" as unicode characters.

Check this:


var stmt = "select “No.”";
stmt = stmt.replace('“', '\\u201c');
stmt = stmt.replace('”', '\\u201d');

console.log(stmt);

about 4 years ago · Juan Pablo Isaza Report

0

There's no need to use the unicode references. Just pass in the quotations as normal, within single quotes.

var stmt = "select “No.”";
stmt = stmt.replace('“', '"');
stmt = stmt.replace('”', '"');

console.log(stmt);

about 4 years ago · Juan Pablo Isaza Report

0

1) It is better to replace all characters in a single go use regex /“|”/g:

var stmt = "select “No.”";
stmt = stmt.replace(/“|”/g, '"');

console.log(stmt);

2) You can also use replaceAll here as:

var stmt = "select “No.”";
stmt = stmt.replaceAll(/“|”/g, '"');

console.log(stmt);

3) You can also replace it using its unicode value as:

var stmt = "select “No.”";
stmt = stmt.replaceAll(/\u201C|\u201D/g, '"');

console.log(stmt);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!