eval returns the value of the variable

eval(string)
parameter description
string    essential. To calculate the string, which contains the statement or expression to be evaluated to execute JavaScript.



Return value : value (if any) obtained by calculating the string.
. 1  var Ll = '01 ' ;
 2  var L2 of = '02' ;
 . 3  var L3 = '03 ' ;
 . 4  var L4 = '04' ;
 . 5  var L5 of = '05 ' ;
 . 6  var L6 of = '06' ;
 . 7  var = '07 L7 of ' ;
 . 8  var L8 of = '08' ;
 . 9  for ( var I =. 1; I <. 9; I ++ ) {
 10    the console.log (the eval ( 'L' + I));   // result is variable L1 values of 01, 02 ......, ...... 08
 . 11 }

 

1  was L1 = '01 ' ;
2  was L2 = '02 ' ;
3  was L3 = '03 ' ;
4  was L4 = '04 ' ;
5  were L5 = '05 ' ;
6  was L6 = '06 ' ;
7  was L7 = '07 ' ;
8  was L8 = '08 ' ;
9  was scar = [];
10  for ( were i = 1; i <9; i ++ ) {
 11    arr.push (eval (L + i));12 is  }
 13 is  the console.log (ARR); \\ [ "01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" ]
14 var STR = ARR .join ( '\ n-' ); \\ If omitted, a comma is used as a separator. join () method for all elements in the array into a string.
15 the console.log (STR); \\ 01 (typeof type string STR) 02 03 04 05 06 07 08

 

Reproduced in: https: //www.cnblogs.com/positive/p/3459161.html

Guess you like

Origin blog.csdn.net/weixin_34174132/article/details/93495705