Jump to content


This topic is now archived and is closed to further replies.


Javascript arrays

Recommended Posts

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.


Share this post

Link to post
Share on other sites
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).

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.