.map()
is designed to both iterate and create a new resulting array.
.each()
is designed to be an iterator (no new array created).
Either will work for plain iteration, though I would argue that the intent of your code is clearer if you are just doing an iteration if you use .each()
since that is its intended and only purpose.
As for functionality differences besides the creation of the array, jQuery's .each()
allows you to terminate the iteration by returning false
from the callback. jQuery's .map()
does not have a way to terminate the iteration.
source - http://stackoverflow.com/questions/22519351/jquery-each-vs-map-without-return
'Development > jQuery' 카테고리의 다른 글
jquery - Using .stop() or .clearQueue() to avoid animation queues in jQuery (0) | 2015.06.15 |
---|---|
jquery - 페이지 상단으로 이동(scroll to top) (0) | 2013.11.01 |
jquery - 태그 감싸기 wrap(), wrapAll(), wrapInner() (0) | 2013.10.29 |
jquery - .attr()와 .prop() (0) | 2013.10.25 |
jquery - fullCalendar events function (1) | 2013.07.29 |