each vs map functions

each vs map functions

by Khadeer Mohammed

JavaScript

function fun1() {
    return this + 1;
}
function fun2(el) {
    return el + 1;
}

var item = [5,4,3,2,1];

var newitem1 = $.each(item, fun1);
var newitem2 = $.map(item, fun2);

document.write('<h1>each vs map functions</h1>');
document.write("["+newitem1+"]"); // [5, 4, 3, 2, 1] 
document.write("<br>["+newitem2+"]"); // [6, 5, 4, 3, 2]