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

后端 未结 7 618
遥遥无期
遥遥无期 2021-02-01 02:10

The following code replaces only one single quote:

7条回答
  •  Happy的楠姐
    2021-02-01 02:50

    You can use a global qualifier (a trailing g) on a regular expression:

    var b = a.replace(/'/g, '"');
    

    Without the global qualifier, the regex (/'/) only matches the first instance of '.

提交回复
热议问题