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
Try: string. replace(/\\\//g, "/");
The backslash() is an escape character in JavaScript. The backslash \ is reserved for use as an escape character in JavaScript. To escape the backslash in JavaScript use two backslashes.
Use the String. replace() method to remove a trailing slash from a string, e.g. str. replace(/\/+$/, '') . The replace method will remove the trailing slash from the string by replacing it with an empty string.
The backslash ( \ ) is an escape character in Javascript (along with a lot of other C-like languages). This means that when Javascript encounters a backslash, it tries to escape the following character. For instance, \n is a newline character (rather than a backslash followed by the letter n).
Use a simple regex to solve it
str = str.replace(/\\/g, '')
Demo: Fiddle
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";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With