Each, ForEach

each

유틸리티 메서드

$.each(object, function(index, item){});
var arr = [ 1, 10, 7, 9, 5 ];
 
$.each(arr, function(index, value) {
  console.log(index + " : " + value);
});

일반 메서드

$(selector).each(function(index, item){})

foreach

Array.forEach(function(value, index, array) {})
var arr = ['item1', 'item2', 'item3'];
arr.forEach(function(value, index, array) {})

some

foreach 와 some은 사용법이 동일하나 차이는 some은 return 이 존재할 경우 for문의 break와 같은 역활을 하지만 foreach는 return의 영향을 받지 않는다.

평점을 남겨주세요
평점 : 2.5
총 투표수 : 1