object as a key javascript 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: javascript variable as object key
var key = "happyCount";
var obj = {};
obj[key] = someValueArray;
myArray.push(obj);