Set.delete() 函数在 JavaScript 中的作用
Set 对象的 delete() 函数接受一个值,并将其从当前 Set 对象中移除。
语法
其语法如下:
setObj.delete()
示例
<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'); document.write("Contents of the Set before deletion:"); document.write("<br>"); for (let item of setObj) { document.write(item); document.write("<br>"); } setObj.delete('JavaFX'); document.write("Contents of the Set after deletion:"); document.write("<br>"); for (let item of setObj) { document.write(item); document.write("<br>"); } </script> </body> </html>
输出
Contents of the Set before deletion: Java JavaFX JavaScript HBase Contents of the Set after deletion: Java JavaScript HBase
广告