The usage of the each function in jquery is similar to that of the map function, but there is still a difference.
An important difference is that each returns the original array and does not create a new array. The map method returns a new array. If map is used without any need, memory may be wasted.
For example:
Var items = [1, 2, 4]; $. each (items, function () {alert ('this is '+ this) ;}); var newItems =$. map (items, function (I) {return I + 1 ;}); // newItems is [2, 3, 4, 5]
When each is used, the original items array is changed. When map is used, items is not changed, but a new array is created.
For example:
Var items = [,]; var itemslessthan1_five = $. map (items, function (I) {// removes all items> 5 if (I> 5) return null; return I ;}); // itemslessthan1_five =, 4, 5]
This is also true when the array needs to be deleted. Therefore, the error of using each or map during deletion is still very serious.