collections 

Send to Kindle
home » snippets » javascript » es6 » collections



Snippets

From: Collecting and Iterating, the ES6 Way

// Maps can be initialized by passing in an iterable value (https://people.mozilla.org/~jorendorff/es6-draft.html#sec-map-iterable)
// Here, we use an Array of Arrays to initialize. The first value in each sub-Array is the new
// Map entry's key, and the second is the item's value.
var typesOfKeys = new Map([
  ['one', 'My key is a string.'],
  ['1', 'My key is also a string'],
  [1, 'My key is a number'],
  [document.querySelector('#log'), 'My key is an object']
]);