Manas Mohapatra
What is difference between jquery .map() and .each()?
By Manas Mohapatra in JQuery on Aug 13 2015
  • Munesh Sharma
    May, 2016 4

    The each method is meant to be an immutable iterator, where as the map method can be used as an iterator, but is really meant to manipulate the supplied array and return a new array.Another important thing to note is that the each function returns the original array while the map function returns a new array. If you overuse the return value of the map function you can potentially waste a lot of memory.

    • 0
  • Manas Mohapatra
    Aug, 2015 13

    Both are jQuery functions which helps to loop over object list(json, array) in helps to loop over object list and also helps to return new array. each() helps only to loop over object list.Secondly you can break iteration in each() but it won't happen in map().var items = [1,2,3,4];$.each(items, function() {alert('this is ' + this); });var newItems = $.map(items, function(i) {return i + 1; });Output: [2,3,4,5]

    • 0

Most Popular Job Functions