View Full Version : what CHARS will kill an Array built dynamically?
BrightNail
03-21-2003, 07:35 PM
hey all,
what characters will muck up a javascript array..
I know....these do..
comma, apostrophe,newline,tab
etc...what else?..I need a list of potentialy "bad" characters..
thanks,
james
beetle
03-21-2003, 08:31 PM
Uhhh, what?
In what context? Any character is valid for an array IF you insert it as a string.
BrightNail
03-21-2003, 10:15 PM
I don't think that is true...
for instance...
tester = new Array ('joe's tavern','here,she said','okay');
that will break..because of the apost. in "joe's" and the comma in "here, she said".......
I have an array being populated on the fly from a database...so, I haev to strip certain characters or my javascript arrays will break..
so, I want them to do this on the app end..so I need all the characters that will break a js array.
brothercake
03-21-2003, 10:33 PM
you just have to escape them
var place = 'Joe\'s apartment';
beetle
03-22-2003, 12:19 AM
The comma should cause no problems at all. And, and as brothercake pointed out, if you insert a character into a string that is identical to it's delimiter, it needs to be escaped with a backslash
var myStr = 'abc"def'; // okay
var myStr = "abd'def"; // okay
var myStr = 'abc'def'; // not okay
var myStr = "abc"def"; // not okay
Those offending characters need escaping
var myStr = 'abc\\'def'; // okay
var myStr = "abd\"def"; // okay
And, as you can see, you are really experiencing a String problem, not an Array problem ;)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.