Last active
June 21, 2017 15:59
-
-
Save sebringj/afb11dd9644fbf0cadb3a051afcd552f to your computer and use it in GitHub Desktop.
JavaScript getKeyList
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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