javascriptsetecmascript-6

Is there a Set literal in JavaScript?


I can make a Set with new Set(), same way I can use the Array or Object or Boolean or Number constructors.

But is there a set literal syntax, like there is for arrays, objects, booleans, numbers etc?


Solution

  • As others have pointed out, there is no Set (or Map) literal syntax yet. There have been a few ideas floating around, in this ES Discuss Thread and in the following twitter discussion.

    A few proposed syntax examples:

    const set = {<1, "two", false>}; // by Brendan Eich
    const set = {. 1, "two", false .}; // by Axel Rauschmayer
    

    There are, as far as I can see, no proposals to implement any of them yet, though.