Sayfalar

6 Aralık 2013 Cuma

JavaScript How To :1- Iterate variables inside of the object

//From the various internet sources.

//Javascript Object ad=> name ; soyad=> surname
var personalInformation = {
    ad:'Önder',
    soyad:'ALTINTAŞ',
    lineOfCodesWritten: 65536

}
//Iterating personalInformation's variables with for loop
// key : 'ad','soyad','lineOfCodeWritten'
// personalInformation['ad'] gives 'Önder' and you can re-set it with:
// personalInformation['ad'] = 'Murtaza'
for (var key in personalInformation){
   value = personalInformation[key];
   console.log(key+":"+personalInformation[key]);
}

Hiç yorum yok:

Yorum Gönder