By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,521 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,521 IT Pros & Developers. It's quick & easy.

Tableau associatif

P: n/a
est-il possible de traiter un tableau de façon "associative" (comme ds PHP ?

Merci;
G.Roydor

exemple : tab ["macle"]

Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Bonjour à Guy Roydor <gu********@nospamlaposte.net> qui nous a écrit :
est-il possible de traiter un tableau de façon "associative" (comme
ds PHP ?

Merci;
G.Roydor

exemple : tab ["macle"]


Oui, par exemple :

tab = new Array();

tab[ "cle1" ] = "valeur1";
tab[ "cle2" ] = "valeur2";
tab[ "cle3" ] = "valeur3";

for( var i = 1; i < 4; i++) {
alert( tab[ "cle"+ i ] );
}

tab[ "cle4" ] = new Array();

tab[ "cle4" ][ "cle4-1" ] = "valeur4-1";
tab[ "cle4" ][ "cle4-2" ] = "valeur4-2";
tab[ "cle4" ][ "cle4-3" ] = "valeur4-3";

etc...

Rq: on ne peut pas, en Javascript, créé des tableaux à double entrée,
ie:

tab[ "cle4", "cle4-1" ] = "valeur4-1"; //==> est invalide

--
Cordialement, Thierry ;-)

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.