By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,446 Members | 3,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,446 IT Pros & Developers. It's quick & easy.

HTML Escape Sequence versus \

P: n/a
Hello,

I'm having problems with the apostrophe character when building a
Javascript array.

I've come up with two different ways to fix the problem. I wondered
if any one had any input as to which approach would be "best
practices" and why.

Approach 1:

var aMyArray = new Array();
aMyArray[aMyArray.length] = new Array('Person's name.',
'',
'False',
'',
'True');

Approach 2:

var aMyArray = new Array();
aMyArray[aMyArray.length] = new Array('Person\'s name.',
'',
'False',
'',
'True');

Thanks,
Eric
Jan 18 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
pr
Eric wrote:
I'm having problems with the apostrophe character when building a
Javascript array.

I've come up with two different ways to fix the problem. I wondered
if any one had any input as to which approach would be "best
practices" and why.

Approach 1:

var aMyArray = new Array();
aMyArray[aMyArray.length] = new Array('Person's name.',
Unless the programmer retains a table of ASCII codes in their head, this
approach is going to be slightly more troublesome to maintain.

[...]
Approach 2:

var aMyArray = new Array();
aMyArray[aMyArray.length] = new Array('Person\'s name.',
This is more normal.

Simplest of all is:

aMyArray[aMyArray.length] = new Array("Person's name.", ...
Jan 18 '08 #2

P: n/a
pr
pr wrote:
Eric wrote:
>aMyArray[aMyArray.length] = new Array('Person's name.',

Unless the programmer retains a table of ASCII codes in their head, this
approach is going to be slightly more troublesome to maintain.
and I should have asked if you really meant ''' or '\u0027'.

See
<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals#Using_Special_C haracters_in_Strings>
<URL:http://www.w3.org/TR/html401/charset.html#h-5.3.1>
Jan 19 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.