What is the difference between a map and each function in jQuery
Answers (1)
Add AnswerDifference between a map and reach function.
$.map | $.each |
map method can be used as an iterator | each method is an immutable iterator |
Return a New array | Return an original array |
Does not have a way to terminate the iteration | Return false to terminate the iteration |
Example:
$(document).ready(function () { var intArray = [1,2,3,4,5]; function functionA( index, element ) { return element * 5; } function functionB( element, index ) { return element * 5; } var result1 = $.each(intArray , functionA); var result2 = $.map(intArray , functionB); document.write('each = ' + result1); document.write('<br>'); document.write('map = ' + result2); });
output:
I hope you guys found something useful ??