Hàm clear () của đối tượng Set xóa tất cả các phần tử khỏi đối tượng Set hiện tại.
Cú pháp
Cú pháp của nó như sau
setObj.clear()
Ví dụ
<html>
<head>
<title>JavaScript Example</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> Đầu ra
Contents of the Set: