# set.isEqualTo()

[JS](../../../..) ⟩ [value](../../..) ⟩ [object](../../../obj)⟩ [built-in](../..) ⟩ [Set](..) ⟩ [extension]() ⟩ .isEqualTo()&#x20;

{% tabs %}
{% tab title="💾 程式" %}
* replit ⟩ [Set Equality](https://replit.com/@pegasusroe/Set-Equality#index.js) (old code)

```javascript
// isEqualSets(a,b)
function isEqualSets(a, b){
    if (a.size !== b.size) return false;
    return Array.from(a).every(elem => b.has(elem));
}

// setA.equal(setB)
Set.prototype.equal = function(setB){
    return isEqualSets(this, setB);
}
```

* :point\_right: [#fan-li](..#fan-li "mention")&#x20;
{% endtab %}

{% tab title="📘 手冊" %}
* array.[every](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)(), [Array.from](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/from)()
* [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#instance_methods)
{% endtab %}

{% tab title="🗣 討論" %}
* [comparing ECMA6 sets for equality](https://stackoverflow.com/questions/31128855/comparing-ecma6-sets-for-equality)
{% endtab %}
{% endtabs %}
