Skip to content

Instantly share code, notes, and snippets.

@battmanz
Last active June 19, 2017 05:16
Show Gist options
  • Select an option

  • Save battmanz/9ffbac3c18c6cf33d97a4ad511129e94 to your computer and use it in GitHub Desktop.

Select an option

Save battmanz/9ffbac3c18c6cf33d97a4ad511129e94 to your computer and use it in GitHub Desktop.
Functions that can be used in place of Map mutator methods.
const map = new Map([
[1, 'one'],
[2, 'two'],
[3, 'three']
]);
// Instead of: map.set(4, 'four');
const map2 = new Map([...map, [4, 'four']]);
// Instead of: map.delete(1);
const map3 = new Map([...map].filter(([key]) => key !== 1));
// Instead of: map.clear();
const map4 = new Map();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment