Tableau associatif

Discussion in 'Javascript' started by Guy Roydor, Feb 13, 2004.

  1. Guy Roydor

    Guy Roydor Guest

    est-il possible de traiter un tableau de façon "associative" (comme ds PHP ?

    Merci;
    G.Roydor

    exemple : tab ["macle"]
     
    Guy Roydor, Feb 13, 2004
    #1
    1. Advertising

  2. Guy Roydor

    Cenekemoi Guest

    Bonjour à Guy Roydor <> 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 ;-)
     
    Cenekemoi, Feb 13, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vianney =?iso-8859-1?Q?Lan=E7on?=

    Calcule l element maximum d'un tableau

    Vianney =?iso-8859-1?Q?Lan=E7on?=, Aug 28, 2003, in forum: C++
    Replies:
    1
    Views:
    407
    Artie Gold
    Aug 29, 2003
  2. spidey12345
    Replies:
    6
    Views:
    946
    Thomas Fritsch
    Feb 8, 2007
  3. eXistenZ|
    Replies:
    1
    Views:
    178
    eXistenZ|
    Jan 24, 2005
  4. G Roydor

    Array Associatif

    G Roydor, Feb 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    73
  5. Alextophi
    Replies:
    13
    Views:
    269
    George
    Sep 8, 2005
Loading...

Share This Page