var fileReader = new FileReader(); fileReader.onload = (function(f) { return function() { dataArray.push({name : f.name, value : this.result}); addImage((dataArray.length-1)); }; })(file);