Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda