JavaScript Map get() method

The JavaScript map get() method is used to retrieve the value of a specified key. Syntax: mapObj.get(key) Parameters: key: It represents the specific key corresponding to which value has to be retrieved. Return: The value corresponds to a specific key. Example: <!DOCTYPE html> <html> <body> <script> var hello=new Map(); hello.set(1,”GOOD MORNING”); hello.set(2,”GOOD AFTERNOON”); hello.set(3,”GOOD EVENING”); … Read more

JavaScript Map forEach() method

The JavaScript map forEach() method is used to execute the specified function once for each key/value pair. Syntax: mapObj.forEach(callback) Parameters: callback: It refers to the function which has to be executed. Example: <!DOCTYPE html> <html> <body> <script> var hello=new Map(); hello.set(1,”GOOD MORNING”); hello.set(2,”GOOD AFTERNOON”); hello.set(3,”GOOD EVENING”); hello.set(4,”GOOD NIGHT”); document.writeln(“Elements are:”+”<br>”); function print(elements) { document.writeln(elements+”<br>”); } … Read more

Map entries() method JavaScript

The JavaScript map entries() method is used to retrieve an object of Map iterator that contains the key-value pair for each element. Note: The iterator object keeps the insertion order of map elements. Syntax: mapObj.entries() Return: An object of Map iterator Example: <!DOCTYPE html> <html> <body> <script> var bday=new Date(“November 16, 1994 21:10:10”); document.writeln(bday.toDateString()); </script> … Read more

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