Return a value from a function using getJSON

Return a value from a function using getJSON

Hi,

I have a json file (detailing file extensions and their mime types)

I want to pass a function a file extension e.g. docx, return its associated mime type and to stop further searching through the json file

This is what I have so far but I'm getting undefined for mType in my function

  1. var fileExt = "docx";
  2. var mimeType = getMimeType(fileExt);

  3. function getMimeType(fileExt) {
  4. var mType;

  5. $.getJSON('json/mimeTypes.json', function(data) {
  6. $.each(data,function(key, value) {
  7. if(key == fileExt) {
  8. mType = value;
  9. }
  10. });
  11. });

  12. return mType;
  13. }

Thanks in advance