--- title: Set.prototype.clear() slug: Web/JavaScript/Reference/Global_Objects/Set/clear tags: - ECMAScript 2015 - JavaScript - Method - Prototype - Reference - set translation_of: Web/JavaScript/Reference/Global_Objects/Set/clear ---
{{JSRef}}

clear() 메서드는 Set 객체를 비웁니다.

{{EmbedInteractiveExample("pages/js/set-prototype-clear.html")}}

구문

mySet.clear();

예제

clear() 사용하기

var mySet = new Set();
mySet.add(1);
mySet.add('foo');

mySet.size;       // 2
mySet.has('foo'); // true

mySet.clear();

mySet.size;       // 0
mySet.has('bar')  // false

명세

Specification Status Comment
{{SpecName('ES2015', '#sec-set.prototype.clear', 'Set.prototype.clear')}} {{Spec2('ES2015')}} Initial definition.
{{SpecName('ESDraft', '#sec-set.prototype.clear', 'Set.prototype.clear')}} {{Spec2('ESDraft')}}  

브라우저 호환성

{{Compat("javascript.builtins.Set.clear")}}

같이 보기