// Call arrayToObj() passing your array and function. function arrayToObj(array, keyValueMap) { var obj = {}; var len = array.length; // Your function will be called for each item in the array. for (var i = 0; i < len; i++) { var curVal = array[i]; // Just like with [].forEach(), your function will be passed the // curent item of the array, its index, and the array it's in. var keyValuePair = keyValueMap(curVal, i, array); // Your function should return a 2-value array with the key // and value for a new property in the object to be returned. obj[keyValuePair[0]] = keyValuePair[1]; } return obj; }