javascript object key with variable code example
Example 1: javascript object as key
var fighters = new WeakMap();
var bruce = {name: 'Bruce Lee'};
var chuck = {name: 'Chuck Norris'};
fighters.set(bruce, 'Jeet Kune Do');
fighters.set(chuck, 'Karate');
console.log(fighters.get(bruce)); // Jeet Kune Do
console.log(fighters.get(chuck)); // Karate
Example 2: js variable for key obj
{
[yourKeyVariable]: someValueArray,
}