I’m trying to construct a javascript array from a db query. Each item in the array is a string that can contain many different characters that mess up the array. Single quotes, double quotes, parens, etc…
Here’s an example of my current output:
var titleList = new Array('Fallout: New Vegas Teaser-Trailer HD','Saints NFC Champions','Best action scene of all time','NJ Lady ep 5: Our Grandma watches Jersey Shore','Australian Banker Caught Looking At Racy Images Of Model Miranda Kerr On Live Television','LEAKED FOOTAGE: New Griswold's "Vacation" Movie?','"A.D." teaser (ZOMBIE ANIMATION)'
…and so on
Is there a special way i can encapsulate each array item so that the title’s characters dont interfere with the JS?
Thanks for your help.
Yes, you can escape these characters. Read about JSON.
Example (Hebrew text in json serialized object):