JavaScript Map delete() method

The JavaScript map delete() method eliminates the specified element from a Map object. Syntax: mapObj.delete() Example: <!DOCTYPE html> <html> <body> <script> var hello=new Map(); hello.set(“GOOD MORNING”); hello.set(“GOOD AFTERNOON”); hello.set(“GOOD EVENING”); hello.set(“GOOD NIGHT”); document.writeln(“Number of elements: “+ hello.size+”<br>”); hello.delete(“GOOD NIGHT”); document.writeln(“Number of elements: “+hello.size); </script> </body> </html>

JavaScript Map clear() method

The JavaScript map clear() method eliminates all the elements from a Map object. Syntax: mapObj.clear() Example: <!DOCTYPE html> <html> <body> <script> var hello=new Map(); hello.set(“GOOD MORNING”); hello.set(“GOOD AFTERNOON”); hello.set(“GOOD EVENING”); hello.set(“GOOD NIGHT”); document.writeln(“Number of elements: “+ hello.size+”<br>”); hello.clear(); document.writeln(“Number of elements: “+hello.size); </script> </body> </html>

JSON.stringify() method

The Javascript handler JSON.stringify() method is used to transform a JSON object into a JSON string representation. Syntax: Json.stringify(value) Parameters value: It represents the value that has to be converted into a JSON string. Return JSON string. Example: <!DOCTYPE html> <html> <body> <script> var details = ‘{ “Name”:”JAI”, “Seat”:”56″, “Coach”:”5A”}’; var passenger = JSON.stringify(details); document.write(passenger); … Read more

JSON.parse() method

The Javascript JSON.parse() method is used to transform a JSON string into a JavaScript object. Syntax: JSON.parse(text) Parameters text: It represents the string to be parsed as JSON. Return JSON object. Example: <!DOCTYPE html> <html> <body> <script> var details = ‘{ “Name”:”JAI”, “Seat”:”56″, “Coach”:”5A”}’; var passenger = JSON.parse(details); document.write(passenger.Name + ” ” + passenger.Seat); </script> … Read more

JavaScript setPrototypeOf() method

The Javascript handler setPrototypeOf() method modifies the prototype of an object. Syntax: setPrototypeOf: function(target, prototype) Parameters: target: It represents the target object. prototype: It represents the new prototype of the object. It can be null. Return: Returns true if the prototype of the object changed successfully otherwise returns false. Example: <!DOCTYPE html> <html> <body> <script> … Read more

JavaScript set() method

The Javascript handler set() method creates a collection of unique items. Syntax: set: function(target, property, value, receiver) Parameters: target: It represents the target object. property: It represents the name or value of the property. value: It represents the new of the property. receiver: It represents the proxy itself. Return: Boolean. Example: <!DOCTYPE html> <html> <body> … Read more

JavaScript preventExtensions() method

The Javascript handler preventExtensions() method traps the Object.preventExtensions method. New properties can not be added to the object when extensions are prevented. Syntax: preventExtensions: function(target) Parameters: target: It represents the target object. Return: Boolean. Example: <!DOCTYPE html> <html> <body> <script> const handler = new Proxy({}, { preventExtensions: function(a) { Object.preventExtensions(a); return !Object.isExtensible(a); }}); document.writeln(‘Value: ‘); … Read more

JavaScript ownKeys() method

The Javascript handler ownKeys() method gives an enum object in return. Syntax: ownKeys: function(target) Parameters: target: It represents the target object. Return: An enumerable object. Example: <!DOCTYPE html> <html> <body> <script> var handler = new Proxy({}, { ownKeys: function(a) { document.writeln(” My favourite fruits are: “); return [‘apple’, ‘mango’, ‘and orange.’]; }}); document.writeln(Object.getOwnPropertyNames(handler)); </script> </body> … Read more

JavaScript isExtensible() method

The Javascript handler isExtensible() method traps for Object.isExtensible(). It is commonly used for logging or auditing calls. Syntax: isExtensible: function(target) Parameters: target: It represents the target object. Return: Boolean. Example: <!DOCTYPE html> <html> <body> <script> const handler={ too:1 } const extent = new Proxy(handler, { isExtensible: function(a) { document.writeln(‘HELLO WORLD! : ‘); return true; }}); … Read more