I have a list of lists that I…

I have a list of lists that I need to flatten to a single list that contains a string representation of each object.

/*
* Flatten a list of lists into a list of string representations of each object
*
* @param {Object[][]} list A list of lists
* @param {Function(Object)} apply Returns a string representation of each element 
*                             in list
* @returns {String[]} A list of string representations of each element in list,  
*                             duplicates excluded
*/
function flatten(list, apply) {
   var result = [];
   var obj = {};
   for(var i = 0; i < list.length; i++) {
       for(var j = 0; j < list[i].length; j++) {
           obj[apply(list[i][j])] = 0;
       }
    }
   for(var e in obj) {
      result.push(e);
   }
   return result;
}

I can call this function with:

var listOfLists= [["Some", "object"], ["Another", "list"]];
var flat = flatten(listOfLists, function(o){
        return o;
    });

The purpose of the apply function is to be able to convert the objects in the list to a string, for example picking out an id that represents each object.