Exploring different ways of accessing property values in JavaScript
$(document).ready(function () {
var itemList = [{ id: 1, name: 'shohel' }, { id: 2, name: 'rana' }, { id: 3, name: 'shipon' }];
//step 1 : accessing property value
for (var i = 0; i < itemList.length; i++) {
var id = itemList[i].id;
}
//step 2 : another way to access property value
for (var i = 0; i < itemList.length; i++) {
var id = itemList[i]['id'];
}
//confused about which syntax is more efficient?
});
Seeking clarity on the best method to retrieve property values in JavaScript. Can you help me decide?