[Javascript] IE work-a-round question (re: checkboxes)

David Dorward david at dorward.me.uk
Sat Apr 12 10:39:27 CDT 2008


On 12 Apr 2008, at 16:34, Claude Schneegans wrote:
>
> But what's the big idea of breaking a string into its character in  
> order
> to make a string with them?

It is a quick and easy way to get at the characters you want from the  
string.

> Especially if those characters are "1" and "1"
> If id[2] and id[3] are "1"s, the expression might very well end into  
> "2"
> (addition) instead of "11" (concatenation).

Only if there is a bug in the JavaScript engine. The data type is  
string, you'd have to do something that converted it to a number  
before that would happen.

 >>> "123"[1] + "123"[2]
"23"

> If you need to extract chars 2 and 3 out of the string id, better use
> the substr() method:
> id2 = "c" + id.substr(2,2);


For the sake of IE, this is true, but treating the string as a  
character array can result in more readable code.

-- 
David Dorward
http://dorward.me.uk/
http://blog.dorward.me.uk/





More information about the Javascript mailing list