Google Apps Script - Convert row data to dictionary

Converting a row data of a google spreadsheet to a dictionary is quite useful. Here is the snippet I wrote this morning:

function rowToDict(sheet, rownumber) {
var columns = sheet.getRange(1,1,1, sheet.getMaxColumns()).getValues()[0];
var data = sheet.getDataRange().getValues()[rownumber-1];
var dict_data = {};
for (var keys in columns) {
var key = columns[keys];
dict_data[key] = data[keys];
}
return dict_data;
}
view raw utils.gs hosted with ❤ by GitHub

With the dictionary format, you can access column data of that row easily, for example:

Logger.log(myDictData["username"]);

Pretty neat huh? \m/