C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Map delete() methodThe JavaScript map delete() method is used to remove all the elements from Map object. SyntaxThe delete() method is represented by the following syntax: mapObj.delete() JavaScript Map delete() method exampleHere, we will understand delete() method through various examples. Example 1Let's see a simple example of delete() method. <script> var map=new Map(); map.set(1,"jQuery"); map.set(2,"AngularJS"); map.set(3,"Bootstrap"); document.writeln("Size before invoking delete() method: "+ map.size+"<br>"); map.delete(2); document.writeln("Size after invoking delete() method: "+map.size); </script> Output: Size before invoking delete() method: 3 Size after invoking delete() method: 2 Example 2Let's see an example to determine whether the map object contains the specified element. <script> var map=new Map(); map.set(1,"jQuery"); map.set(2,"AngularJS"); map.set(3,"Bootstrap"); document.writeln("Element present before invoking delete() method: "+ map.has(2)+"<br>"); map.delete(2); document.writeln("Element present after invoking delete() method: "+map.has(2)); </script> Output: Element present before invoking delete() method: true Element present after invoking delete() method: false
Next TopicJavaScript Math
|