HTML Escape Sequence versus \

E

Eric

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
 
P

pr

Eric said:
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.", ...
 
D

Dr J R Stockton

In comp.lang.javascript message <509dceed-f73b-454e-8827-6cde93de11bf@i7
2g2000hsd.googlegroups.com>, Fri, 18 Jan 2008 06:57:45, Eric
aMyArray[aMyArray.length] = new Array('Person's name.',

That array element does not contain an apostrophe, or anything like it;
it only contains something which, under some circumstances, is converted
into that. Use "" for quoting in this case at least, and use ' before
s. Or write "Personal name".

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,127
Latest member
CyberDefense
Top