Jump to content


Javascript arrays

  • Please log in to reply
1 reply to this topic

#1 radalin

  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 12 October 2006 - 01:50 PM

I have question about javascript and array system. I'm using javascript in my web site and I would like to enable a language selection on it. I'm using language options from php side. an associative array, containing values like $lang["Hello"] => "Hello", and this goes on.

Is there a way to do this with javascript? I mean is there a such an assosiative array option in javascript (which I do not think it's possible.). I have intended to use a getLang function which takes an argument about lang and with switch statements it returns the right value. Well that's ok but it will take a lot of time if I have thousand cases. Any idea is welcome.

Roy Simkes
Yet Another Parkyeri Developer

#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 12 October 2006 - 03:38 PM

Yes, JS support associative arrays a.k.a. hashes:

var myAA = {};
myAA['key1'] = 'value1';

Strictly speaking, you can mix arrays and hashes, but don't (read: don't use numbers as the keys).
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users