EDIT: This string is a part of json and i am writing it onto a file. In that json file i see the escape charaters. With console.log, I don't see any escape character.
I am trying to concatenate a string such that I get the following output:
"OR("1admin", "2admin")"
But the output I keep on getting is
"OR(\"1admin\", \"2admin\")"
Sample code
var str = "OR("
for (let i = 1; i < 3; i++) {
str += '"' + i + 'admin' + '", ';
}
str = str.trim().substring(0, str.length - 2).concat(')')
console.log(str)
I have tried using regex and string split. eg.
.replace(/'/g, '"') This when i tried something like this "'" + i + "admin" + "', " and tried to replace ' with "
.split('\\').join('').trim() This also didn' work.
What am I doing wrong?
"OR("1admin", "2admin")"is not a syntactically correct string. The second one on the other hand is a string with the character sequence you want: i.e.'O', 'R', '(', '"', .... In other words, you already got the right result. The string"\""is the string consisting of the character'"'. A backlash character '\' is required to escape the '"' character so that it doesn't break string parsing early.