rewriting _.each function in Javascript not returning

Im trying to sharpen my skills in JS and rewriting the underscore.js utility functions. I'm stuck on the first one: each. This is what I have so far but when I run it in node, nothing is returned from iterator() being passed to each()? Please help

//_.each(list, iteratee, [context]); iteratee(element,index,list);

var arr = [1,2,3,4];

var each = function(list, iteratee) {
    for (var i = 0; i < list.length; i++) {
        iteratee(list[i], i, list);
    }
}

var iterator = function(element, i, list){
    return element * 2;
}

each(arr,iterator);

What am I doing wrong and what rewriting these functions in the future, what is the best way to do it? Thanks.

For your each function to return something you actually need to return something:

var arr = [1,2,3,4];

var each = function(list, iteratee) {
    for (var i = 0; i < list.length; i++) {
        // Write return value back to array
        list[i] = iteratee(list[i], i, list);
    }
    // return array
    return list;
}

var iterator = function(element, i, list){
    return element * 2;
}

each(arr,iterator);

This would return the array, what underscore and other popular libraries are doing is returning a wrapped set to enable chaining(_.each().map().bla()). All these libraries(underscore, lodash) are open source, so i recommend to actually look at the source to understand how they operate.