JavaScript 中的 Set.clear() 函数
htmljavascriptprogramming scripts更新于 2024/10/13 22:04:17
Set 对象的 clear() 函数会从当前 Set 对象中删除所有元素。
语法
其语法如下
setObj.clear()
示例
<html>
<head>
<title>JavaScript 示例</title>
</head>
<body>
<script type="text/javascript">
const setObj = new Set();
setObj.add('Java');
setObj.add('JavaFX');
setObj.add('JavaScript');
setObj.add('HBase');
setObj.clear();
document.write("Contents of the Set:");
for (let item of setObj) {
document.write(item);
document.write("<br>");
}
</script>
</body>
</html>
输出
Contents of the Set:
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

