Map 對象的 clear() 函數從當前 Map 對象中刪除所有元素。
用法
其語法如下
mapVar.clear()
示例
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var mapVar = new Map();
mapVar.set('1', 'Java');
mapVar.set('2', 'JavaFX');
mapVar.set('3', 'HBase');
mapVar.set('4', 'Neo4j');
var map = mapVar.clear();
document.write("Size of the map object:"+mapVar.size);
</script>
</body>
</html>
輸出
Size of the map object:0
示例
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var mapVar = new Map();
mapVar.set('1', 'Raju');
mapVar.set('2', 'Ram');
mapVar.set('3', 'Rahim');
mapVar.set('4', 'Robert');
document.write("Size of the map:"+mapVar.size);
var map = mapVar.clear();
document.write("<br>");
document.write("Size of the map after clearing its contents using clear() function:"+mapVar.size);
</script>
</body>
</html>
輸出
Size of the map:4 Size of the map after clearing its contents using clear() function:0
相關用法
- JavaScript Map.delete()用法及代碼示例
- JavaScript Map.entries()用法及代碼示例
- JavaScript Map.has()用法及代碼示例
- JavaScript Map.forEach()用法及代碼示例
- JavaScript Map.keys()用法及代碼示例
- JavaScript Map.size屬性用法及代碼示例
- JavaScript Map set()用法及代碼示例
- JavaScript Map delete()用法及代碼示例
- JavaScript Map forEach()用法及代碼示例
- JavaScript Map keys()用法及代碼示例
- JavaScript Map values()用法及代碼示例
- JavaScript Map has()用法及代碼示例
- JavaScript Map get()用法及代碼示例
- JavaScript Map clear()用法及代碼示例
- JavaScript Map entries()用法及代碼示例
- JavaScript Math abs()用法及代碼示例
- JavaScript Math hypot()用法及代碼示例
- JavaScript Math.tanh()用法及代碼示例
注:本文由純淨天空篩選整理自Samual Sam大神的英文原創作品 Map.clear() function in JavaScript。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。