add Method (Set)

add Method (Set) (JavaScript)


Adds a new element to a set.



Required. A Set object.


Required. New element of the Set.

The new element can be of any type and must be unique. If you add a non-unique element to a Set, the new element will not be added to the collection.


The following example shows how to add members to a set and then retrieve them.

var s = new Set();
s.add("Thomas Jefferson");
s.add("founding father");

s.forEach(function (item) {
    document.write(item.toString() + ", ");

// Output:
// Thomas Jefferson, 1776, founding father,


Supported in the Internet Explorer 11 standards document mode. Also supported in Store apps (Windows 8.1 and Windows Phone 8.1). See Version Information.

Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Not supported in Windows 8.

© 2016 Microsoft