Re: Dynamic variable names
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Dynamic variable names

From: Richard Cornford <Richard@litotes.demon.co.uk>
Date: Wed Nov 16 2005 - 10:07:30 CET

RobG wrote:
> vallini@gmail.com wrote:
<snip>
>> Yet if you'd loop it as an array
>> for(var i=0; i<a.length;i++){alert((typeof i)+' '+(typeof a[i]))}
>> that will rerturn NUMBER NUMBER
>
> That doesn't prove anything, i is declared as a number and
> nothing is done to change its type.
<snip>

A more meaningful test would be using - for(prop in obj) - at then the
type of the value of prop is not externally defined. If you do:-

var z = [1,2,3,4];
for(var prop in z){
    alert((typeof prop));
}

- you get 'string' reported 4 times, which would not be expected to be
the case unless an array's 'array index' property names were strings.

Richard.
Received on Mon Nov 21 03:31:13 2005