Re: Select 1 value from multiple...
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: Select 1 value from multiple...

From: Darren <darren@notathome.net>
Date: Wed Aug 10 2005 - 12:20:33 CEST

"Noozer" <dont.spam@me.here> wrote in message
news:zcjKe.172865$s54.111428@pd7tw2no...
> I want to return one of several values, based on the value of a variable.
>
> Is there a compact way to write this? Something like:
>
> var J=5;
> var K= {"One","Two","Three","Four","Five","Six"} [J] ;
>
>
> ... so K would hold "Five" in this case.
>
> Thx

Use an array.
var K=new Array("One","Two","Three","Four","Five","Six");
var J=4;
document.write(K[J]);
would produce 'five' remember that arrays start with a zero offset

Best wishes

Darren
>
>
Received on Mon Oct 24 02:13:59 2005