String Indexing vs Symbol Indexing

Edit on GitHub

Setup

const strmap = {};
const noop = () => {};

for (let i = 0; i < 50; i++) {
  strmap['someLongEventName' + i] = [];
}

strmap['theTargetEventName'] = [];

const symmap = [];

for (let i = 0; i < 50; i++) {
  symmap[Symbol()] = [];
}

const theTargetEventSymbol = Symbol();
symmap[theTargetEventSymbol] = [];

Tests

  • String Indexing

    strmap['theTargetEventName'].push(noop);
  • Symbol Indexing

    symmap[theTargetEventSymbol].push(noop);