javascript 动态给变量名赋值 方法 代替 eval
javascript 动态给变量名赋值 方法
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS动态给变量赋值方法</title> </head> <body> <script type="text/javascript"> var mark = { a1:1, a2:2, a3:3 } var id = 1; var sn = (new Function("","return mark.a"+id))(); console.log(sn); </script> </body> </html>