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

clear() 메서드는 Map 객체의 모든 요소를 제거합니다.

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

구문

myMap.clear();

예제

clear() 사용하기

var myMap = new Map();
myMap.set('bar', 'baz');
myMap.set(1, 'foo');

myMap.size;       // 2
myMap.has('bar'); // true

myMap.clear();

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

명세

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

브라우저 호환성

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

같이 보기