This is a bad reason to try to do what you’re doing: you’re obfuscating to save space. Make things obvious, not clever and non-obvious. Anyway:
If you want to dynamically access an object:
obj {
A: 97,
a: 97,
}
Wherever your want to access:
obj["a"| "A"]
Or maybe you use a function:
function getCode (obj, char) {
return obj[char.toLowerCase()]
}
Then you don’t need to have multiple keys.
obj {
a: 97,
};
getCode (obj, "A")
getCode (obj, "a")
However, if it’s literally case-insensitive keys, JS allows it, this is how you do that:
const caseInsensitiveKeyHandler = {
get: function (obj, prop) {
if (prop.toLowerCase() in obj) {
return obj[prop.toLowerCase()];
}
};
Then if it’s like your example
var myObj = new Proxy(obj, caseInsensitiveKeyHandler);
And use myObj instead of obj. Note this is normally a super bad idea: it will work perfectly, and you will get a object that accepts case insensitive keys, but it is reflection, and you make things incredibly non-obvious.