いくつかの jquery 変数を動的に作成したい。私のコードではループがあり、ループ値を使用していくつかの変数を作成したいと考えています。これが私のサンプルコードです。
array=["student","parent","employee"]
$.each(user_types, function( index, value ){
var value+"_type" // this is the type of variable i want to build.
})
私はeval関数について見つけました。そのコードは次のようになります。
var type = "type"
eval("var pre_"+type+"= 'The value of dynamic variable, val';");
alert(pre_type) // this gives 'The value of dynamic variable, val' in alert box.
.jsファイルのコーディング中に eval 関数が優先されないことを読んだので、別の方法はありますか。