1.

What are event handlers in JavaScript?

Answer»

When data is sent to a web server, it has to be in the form of string. The JSON.stringify() method is USED in JavaScript to convert an object to string.

Let’s say we have the following object in JavaScript:

VAR ob = { deptname: "Finance", deptid: 2, deptlocation: "East", deptEmployees: 150 };

Now use the JSON.stringify() method to convert the above object into string:

var res = JSON.stringify(ob);

Now, display it with INNERHTML. Let us SEE the example: 

<!DOCTYPE html> <html> <body> <h2>JSON String</h2> <p id="myid"></p> <script> var ob = { deptname: "Finance", deptid: 2, deptlocation: "East", deptEmployees: 150 }; var res = JSON.stringify(ob); document.getElementById("myid").innerHTML = res; </script> </body> </html>

The output generates the string: 



Discussion

No Comment Found