This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Map.prototype.clear()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Itโ€™s been available across browsers since โจ2015๋…„ 7์›”โฉ.

Map์˜ clear() ๋ฉ”์„œ๋“œ๋Š” ํ•ด๋‹น Map์˜ ๋ชจ๋“  ์š”์†Œ๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.

์‹œ๋„ํ•ด ๋ณด๊ธฐ

const map1 = new Map();

map1.set("bar", "baz");
map1.set(1, "foo");

console.log(map1.size);
// Expected output: 2

map1.clear();

console.log(map1.size);
// Expected output: 0

๊ตฌ๋ฌธ

js
clear()

๋งค๊ฐœ๋ณ€์ˆ˜

์—†์Œ.

๋ฐ˜ํ™˜ ๊ฐ’

์—†์Œ(undefined).

์˜ˆ์ œ

clear() ์‚ฌ์šฉํ•˜๊ธฐ

js
const myMap = new Map();
myMap.set("bar", "baz");
myMap.set(1, "foo");

console.log(myMap.size); // 2
console.log(myMap.has("bar")); // true

myMap.clear();

console.log(myMap.size); // 0
console.log(myMap.has("bar")); // false

๋ช…์„ธ์„œ

Specification
ECMAScriptยฎ 2026 Language Specification
# sec-map.prototype.clear

๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ

๊ฐ™์ด ๋ณด๊ธฐ