Simplest way to merge ES6 Maps/Sets?

前端 未结 13 1307
广开言路
广开言路 2020-11-29 17:24

Is there a simple way to merge ES6 Maps together (like Object.assign)? And while we\'re at it, what about ES6 Sets (like Array.concat)?

13条回答
  •  无人及你
    2020-11-29 18:03

    Transform the sets into arrays, flatten them and finally the constructor will uniqify.

    const union = (...sets) => new Set(sets.map(s => [...s]).flat());
    

提交回复
热议问题