It's hard to describe this question in the title, as an example will make sense of what I'm trying to do.
I have a JS object that I want to add to:
jsTestObj = [ ]
On each call to strings of data, I want to add a key and a value pair:
var pushTestObj = { };
pushTestObj["myKey"] = "MyName";
pushTestObj["myValue"] = "I call myself "Joe""; // these strings may have apostrophes, quotes, or even comments that are legit
jsTestObj.push(pushTestObj);
I need to retain all quotes or parenthesis in these fields (and comments, which are also possible and match JS comments). In a sense, I am looking for a possible function (method) that simply wraps the string like:
pushTestObj["myValue"] = wrapStringMethodToRetainCharacters(I call myself "Joe");
Where JS will know it's a string in the value "myValue" and retain the quotes, apostrophes and comments, while still storing it in a string.
Escape Characters
This will work for quotes and apostrophes; what about comments. For example:
var pushTestObj = { };
pushTestObj["myKey"] = "MyName";
pushTestObj["myValue"] = "/* He's "different" */ Sometimes David; // these strings may have apostrophes, quotes, or even comments that are legit
jsTestObj.push(pushTestObj);