Remove all backslashes in Javascript

2019-02-13 20:06发布

How to remove all backslash in a JavaScript string ?

var str = "one thing\\\'s for certain: power blackouts and surges can damage your equipment.";

I want output like

one thing's for certain: power blackouts and surges can damage your equipment.

Update:

I am scrapping data from page with help of JavaScript & displaying on fancy-box popup.

please help me on this

4条回答
一夜七次
2楼-- · 2019-02-13 20:18

Use a simple regex to solve it

str = str.replace(/\\/g, '')

Demo: Fiddle

查看更多
放荡不羁爱自由
3楼-- · 2019-02-13 20:28

How do I do string replace in JavaScript to convert ‘9.61’ to ‘9:61’?

var str = "one thing\\\'s for certain: power blackouts and surges can damage your equipment.";

str.replace("\", "");
查看更多
▲ chillily
4楼-- · 2019-02-13 20:30

Regexs are great str.replace(/\\/g,'')

查看更多
爷的心禁止访问
5楼-- · 2019-02-13 20:35

This is the answer according to the title as the title is "Remove all slashes in Javascript" not backslashes. So here is the code to remove all the slashes from a string in JavaScript.

str = '/mobiles-phones/.png';
str.replace(/\//g, "")//output would be "mobiles-phones.png";
查看更多
登录 后发表回答