Js eval function usage, conversion between js objects and strings., evaljs
The js eval function is used to convert js objects and strings.
JavaScript eval () function JavaScript global function Definition and usage
The eval () function calculates the JavaScript string and runs it as script code.
If the parameter is an expression, the eval () function executes the expression. If the parameter is a Javascript statement, eval () executes the Javascript statement.
Syntax eval (
String)
Parameters |
Description |
String |
Required. The string to be calculated, which contains the JavaScript expression to be calculated or the statement to be executed. |
<! DOCTYPE html> <body> <script> var te = new Object (); te. a = 'fff'; te. B = 100; eval ("x = 10; y = 20; document. write (x * y) "); document. write ("<br>" + eval ("2 + 2"); document. write ("<br>" + eval (x + 17); var str = JSON. stringify (te); alert (str); eval ('He ('+ str +'); function he (va) {var str = JSON. stringify (va); alert (str); var obj = JSON. parse (str); // converts a json string to an alert (obj);} </script> </body>