Skip to content

Instantly share code, notes, and snippets.

@sebringj
Last active June 21, 2017 15:59
Show Gist options
  • Save sebringj/afb11dd9644fbf0cadb3a051afcd552f to your computer and use it in GitHub Desktop.
Save sebringj/afb11dd9644fbf0cadb3a051afcd552f to your computer and use it in GitHub Desktop.
JavaScript getKeyList
/*
use like so:
let keyList = getKeyList("a", "b", "c")
console.log(keyList[0]) // "a"
console.log(keyList.index["a"]) // 0
*/
function getKeyList() {
let arr = [].slice.call(arguments);
arr.index = {};
arr.forEach((key, i) => {
arr.index[key] = i;
})
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment