Comment fait on pour définir un tableau d'objets ?
le but est d'obtenir une structure du type :
tableau[x].hauteur
tableau[x].quantité
tableau[x].lieu
etc...
je cherche mais ne trouve point ! ça doit pourtant être simple !
merci d'avance.
Version imprimable
Comment fait on pour définir un tableau d'objets ?
le but est d'obtenir une structure du type :
tableau[x].hauteur
tableau[x].quantité
tableau[x].lieu
etc...
je cherche mais ne trouve point ! ça doit pourtant être simple !
merci d'avance.
??Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 <script type="text/javascript"> function mon_objet(quelconque){ this.signe_particulier=quelconque; this.trop_banal=function(){ return (typeof this).replace(/^./,"a") + " et " + this.signe_particulier; } } var tableau=new Array(); tableau[0]=new mon_objet("nul"); tableau[1]=new mon_objet("inutile"); for(i in tableau){ alert(tableau[i].trop_banal()) } </script>
Merci et a bientot pour la prochaine question !
Probablement que tu n'utilises pas le bon mot clé.Citation:
Envoyé par lacsap49
Dans ce cas actuel, le mot clé est JSON (JavaScript Object Notation):
http://developer.mozilla.org/fr/docs/La_notation_JSON (fr)
http://www.crockford.com/JSON/ (en)
http://en.wikipedia.org/wiki/JSON (en)
Bonne chance :wink: