JavaScript Feature Reference: Set
Object Web Browser Support Test
1. Introduction
In this web page there are two web browser JavaScript feature support tests; 1.) a feature implementation test, and 2.) a feature capability test. First, the implementation test is run. The implementation test determines if the web browser recognizes the JavaScript Set
object. The implementation test is a simple test for the presence of web browser support, and a definitive test for the absence of web browser support. If the web browser does not recognize the JavaScript Set
object, the testing is stopped and the implementation test reports: Fail (no support): The web browser does not recognize the JavaScript
Set
object. The web browser does not support the JavaScript Set
object.
If the web browser recognizes the JavaScript Set
object, the capability test is run. The capability test determines if the web browser's implementation of the JavaScript Set
object includes support for at least one Set
object capability. The capability test is a more definitive, albeit not an all inclusive, test for the presence of web browser support. If the web browser's implementation of the JavaScript Set
object includes support for the tested capability, the capability test reports: Pass (at least partial/possibly full support): The web browser recognizes the JavaScript
If the web browser's implementation of the JavaScript Set
object, and supports at least one Set
object capability. The web browser at least partially/possibly fully supports the JavaScript Set
object. Positive determination of full web browser support is beyond the scope of this test.Set
object does not include support for the tested capability, the capability test reports: Pass/Fail (partial support): The web browser recognizes the JavaScript
Set
object, but does not support at least one Set
object capability. The web browser partially supports the JavaScript Set
object.
The web browser support test source code is shown in Section 2.1. The web browser support test source code is run in Section 2.2, which shows the web browser support test result.
1.1. Set
Object Web Browser Support
Pass (at least partial/possibly full support):
ED12+, FF19+, CH39+, OP26+.Pass/Fail (partial support):
IE11.Fail (no support):
IE10-, SF5.1.7-.
1.2. Abbreviations
- IE = Internet Explorer.
- ED = Edge Legacy 12 - 18 (EdgeHTML based) and Edge 79+ (Chromium based).
- FF = Firefox.
- SF = Safari.
- CH = Chrome.
- OP = Opera.
2. Set
Object Web Browser Support Test
2.1. Web Browser Support Test Source Code
<p id='testId'><b>Fail</b> (no support): The web browser does not recognize the JavaScript <code>Set</code> object. The web browser does not support the JavaScript <code>Set</code> object.</p><!-- Hard code Fail because web browser no support error stops JavaScript execution. --> <script> var setOne = new Set(); // Empty set. Identical to var setOne = new Set(null);. setOne is Set(0) {}. var setTwo = new Set([1, 2, 3, 4]); // setTwo initialized with an array. setTwo is Set(4) {1, 2, 3, 4}. IE11 does not support sets initialized with an iterable. IE11 mistakenly reports sets initialized with an iterable as [object Object] {size: 0}. Hence, IE11 Pass/Fail (partial support). var arrayLiteralOne = [1, 2, 3, 4]; var arrayLiteralTwo = [1, 2, 3, 1, 2, 4]; var string = "123124"; var setThree = new Set(arrayLiteralOne); // setThree initialized with an array. setThree is Set(4) {1, 2, 3, 4}. var setFour = new Set(arrayLiteralTwo); // setFour initialized with an array. Only unique values added. setFour is Set(4) {1, 2, 3, 4}. var setFive = new Set(string); // setFive initialized with a string. Only unique values added. setFive is Set(4) {"1", "2", "3", "4"}. var setSix = new Set(setTwo); // setSix initialized with a set. setSix is Set(4) {1, 2, 3, 4}. if (window.setOne){ // Identical to if (setOne). var element = document.getElementById("testId"); setOne.add(1); // Item with value 1 added to setOne. setOne is Set(1) {1}. setOne.add(2); // Item with value 2 added to setOne. setOne is Set(2) {1, 2}. setOne.add(3); // Item with value 3 added to setOne. setOne is Set(3) {1, 2, 3}. setOne.add(3); // setOne has item with value 3. Not unique. Nothing added. setOne is Set(3) {1, 2, 3}. setOne.add("3"); // String, not Number. Unique. Item with value "3" added to setOne. setOne is Set(4) {1, 2, 3, "3"}. var arrayLiteral = [1, 2, 3]; var objectLiteral = {propertyOne: 1, propertyTwo: 2, propertyThree: 3}; setOne.add(arrayLiteral); // Item with value arrayLiteral added to setOne. setOne is Set(5) {1, 2, 3, "3", arrayLiteral}. setOne.add(objectLiteral); // Item with value objectLiteral added to setOne. setOne is Set(6) {1, 2, 3, "3", arrayLiteral, objectLiteral}. setOne.delete(1); // Item with value 1 removed from setOne. setOne is Set(5) {2, 3, "3", arrayLiteral, objectLiteral}. setOne.delete(3); // Item with value 3 removed from setOne. setOne is Set(4) {2, "3", arrayLiteral, objectLiteral}. setOne.delete(3); // setOne does not have item with value 3. Nothing removed. setOne is Set(4) {2, "3", arrayLiteral, objectLiteral}. setOne.delete(arrayLiteral); // Item with value arrayLiteral removed from setOne. setOne is Set(3) {2, "3", objectLiteral}. setTwo.clear(); // Remove all items from setTwo. setTwo is Set(0) {}. if ((setOne.size === 3) && (setOne.has(1) === false) && (setOne.has(2) === true) && (setOne.has(3) === false) && (setOne.has("3") === true) && (setOne.has(arrayLiteral) === false) && (setOne.has(objectLiteral) === true) && (setTwo.size === 0) && (setThree.size === 4) && (setFour.size === 4) && (setFive.size === 4) && (setSix.size === 4)){ element.innerHTML = "<b>Pass</b> (at least partial/possibly full support): The web browser recognizes the JavaScript <code>Set</code> object, and supports at least one <code>Set</code> object capability. The web browser at least partially/possibly fully supports the JavaScript <code>Set</code> object. Positive determination of full web browser support is beyond the scope of this test."; } else { element.innerHTML = "<b>Pass/Fail</b> (partial support): The web browser recognizes the JavaScript <code>Set</code> object, but does not support at least one <code>Set</code> object capability. The web browser partially supports the JavaScript <code>Set</code> object."; } } </script>
2.2. Web Browser Support Test Result
Fail (no support): The web browser does not recognize the JavaScript Set
object. The web browser does not support the JavaScript Set
object.