1. Calculating strings
Example: a formula for a string type----a pure number
1 var str = ' 1 ' + ' 2 ' + ' 3 '; 2 var count = eval (str); 3 document.write (count); // at this point count will be calculated as 6.
Another example: the mix of characters and numbers
var code = ' x ' + 1; var count = eval (code);d ocument.write ("count=" +count); // count=x1
2. Convert a string to an array/json/object
This is because the JSON string that is returned cannot be parsed as an array when the project is written, so it can be traversed like an array by using the eval transform.
var array = eval ("[" +data+ "]"); // at this point the conversion for array // But whether it can be converted to exactly the desired array depends on the specifics of the returned data, so be sure to remember the output to see if it satisfies var object = eval (' (' + str+ ') '); // convert to an object var json = eval (' {' +str+ '} '); // Convert to JSON // this and the previous conversion to the object, should be the same when used, please test, depending on the situation
3. Execute JavaScript code.
var s= ' ss 'function Fun () {eval (' var s= ' xx '); Here is the equivalent of var s = "xx"; // output SS
Reference: http://www.jb51.net/article/30008.htm
Only as a note in the collation here, not fully written and incorrect, please advise ~ ~
The role of JS Eval ()