|
The following Script shows the addressing properties of the array elements <Script language=JavaScript> <!-- var demo=new Array(); demo['a']='q' demo['b']='w' demo['c']='e' demo['d']='r' demo['e']='t' demo['f']='y' document.write(demo.b) document.write(demo['b']) //--> </Script> This Script returns : The output of conditional expressions in the right side cell shows how the array the_info[Info] refill its locations with the very values of array Info[i] e Value[i] |
<Script language=JavaScript> /* Another view */ <!-- Here the_info[Info] array is artificially generated. the_info=new Array(); for (i = 0; i < 3; i++) { var Info = new Array('User','age','tel');// Left side elements Info=Info[i]; var Value = new Array('vittorio','53','0881 631796'); //...Right Value=Value[i]; the_info[Info] = Value; document.write(the_info[Info]) if(the_info.User==Value) document.write(the_info.User+' ') if(the_info.age==Value) document.write(the_info.age+' ') if(the_info.tel==Value) document.write(the_info.tel) } document.write(the_info['age']) // Returns : --> </Script> ( See source code ) |
| When the interpreter runs down the Script i=[0] and get into loop body , finds at first place : 'User' then : 'vittorio' and when the new array is reached ( i.e. : the_info[Info] = Value ) releases the values into the declared array ( where-from these will be at disposal for retrieving ), then the interpreter re-enter the loop ... i=[1] and releases : 'age' & '53' ; and later ... i=[2] releases : 'tel' & '0881 631796' | |
|
<Script language=JavaScript> <!-- var information=new Array(); information[0]="a" information[1]="" information[2]="c" information[3]="d" for(i=0; i < information.length; i++) {document.write(''+information[i]+'<br>')} document.write(information.length) //--> </Script> |
<Script language=JavaScript> <!-- var info=new Array('user','age','phone'); for(i=0; i < info.length; i++) {document.write(info[i]+'<br>')} document.write(info[1]) //--> </Script> |
| ...bis Top |
|
<Script language=JavaScript> <!-- var Utente = new Array() Utente[0] = 'Vittorio Ognissanti' Utente[1] = 'Chris Grundy' Utente[2] = 'Michele Ognissanti' Utente[3] = 'Potito Potenza' var Login = new Array() Login[0] = 'vittorio qwerty' Login[1] = 'vittorio qwerty' Login[2] = 'michele perdifiato' Login[3] = 'pinco pallino' var Dati = new Array() Dati[0] = 'Foggia-Italia' Dati[1] = 'Chester-England' Dati[2] = 'Taranto-Italia' Dati[3] = 'Potenza-Italia' |
function getLogin() {var UN=document.entryForm.entry.value for(i=0; i< Utente.length; i++) { if(Utente[i] == UN){ break } } alert("I dati di Login sono " +Login[i] +'.') } function getDati() {var UN=document.entryForm.entry.value for(i=0; i< Utente.length; i++) { if(Utente[i] == UN){ break } } alert("I dati dell\'utente sono : " +Dati[i] +'.') } //--> </Script> <a href=javascript:getLogin()>Call Login</a> <a href=javascript:getDati()>Call Dati</a>
|