Remove Backslashes from JSON Data in JavaScript or jQuery
var str = \"{\"data\":\"{\\n \\\"taskNames\\\" : [\\n \\\"01 Jan\\\",\\n \\\"02 Jan\\\",\\n \\\"03
Your string is invalid, but assuming it was valid, you'd have to do:
var finalData = str.replace(/\\/g, "");
When you want to replace all the occurences with .replace
, the first parameter must be a regex, if you supply a string, only the first occurrence will be replaced, that's why your replace wouldn't work.
Cheers