The js eval function uses js objects and string interconversion instances

  • 2021-07-26 06:32:34
  • OfStack

JavaScript eval () Function JavaScript Global Function

Definition and usage

The eval () function evaluates the JavaScript string and executes it as script code.

If the argument is 1 expression, the eval () function executes the expression. If the parameter is an Javascript statement, eval () executes an Javascript statement.

Grammar

eval(string)

参数 描述
string 必需。要计算的字符串,其中含有要计算的 JavaScript 表达式或要执行的语句。


<!DOCTYPE html>
<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); // You can set the json String is converted to json Object  
 alert(obj);

}

</script>

</body>
</html>			

Related articles: