Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace single quotes with double quotes in JavaScript?

Tags:

javascript

The following code replaces only one single quote:

var a = "[{'column1':'value0','column2':'value1','column3':'value2'}]";  var b = a.replace("'", "\"");  console.log(b);
like image 983
GaneshT Avatar asked May 08 '13 21:05

GaneshT


People also ask

How do you write double quotes in JavaScript?

to show double quote you can simple use escape character("\") to show it.

How do I bypass a single quote in JavaScript?

We can use the backslash ( \ ) escape character to prevent JavaScript from interpreting a quote as the end of the string. The syntax of \' will always be a single quote, and the syntax of \" will always be a double quote, without any fear of breaking the string.

How do I change the apostrophe in JavaScript?

replace(/'/g, 'A');

Are single and double quotes the same JavaScript?

They are the same thing In JavaScript, a string is a sequence of characters enclosed in single or double quotes. The choice of quoting style is up to the programmer, and either style has no special semantics over the other.


1 Answers

var a = "[{'column1':'value0','column2':'value1','column3':'value2'}]";  var b = a.replace(/'/g, '"');  console.log(b);

Edit: Removed \ as there are useless here.

like image 143
RafH Avatar answered Sep 23 '22 18:09

RafH