JS bulit-in for-in vs jQuery.each()

2312 月

JS bulit-in for-in vs jQuery.each()

JS bulit-in for-in:
程式碼:

if (data.station) {
    for (var key in data.station) {
        alert('for-in: ' + data.station[key]['id'] + ': ' + data.station[key]['name']);
    }
}

vs

jQuery.each():
程式碼:

if (data.station) {
    $.each(data.station, function(idx, val) {
        alert('$.each: ' + val.id + ': ' + val.name);
    });
}
Posted by admin  Posted on 23 12 月 
  • JavaScript
  • Post Comments 0