map vs dic
by Maxim_Wolf
JavaScript
const DictionaryCO = {};
const DictionaryMap = new Map();
const aKey = 'k1';
const aValue = 'v1';
const bKey = {x:1};
const bValue = 'v2';
const cKey = {y:2};
const cValue = 'v3';
DictionaryCO[aKey] = aValue;
DictionaryCO[bKey] = bValue;
DictionaryCO[bKey] = bValue;
DictionaryMap.set(aKey, aValue);
DictionaryMap.set(bKey, bValue);
DictionaryMap.set(cKey, cValue);
console.log('a object', DictionaryCO[aKey]);
console.log('b object', DictionaryCO[bKey]);
console.log('c object, oops!', DictionaryCO[cKey]);
console.log('a map', DictionaryMap.get(aKey));
console.log('b map', DictionaryMap.get(bKey));
console.log('c map', DictionaryMap.get(cKey));