var text = "abcd"; function str_rand() { return "f"+i + " => " + text[i] } for (var i = 0; i < text.length; i++) { eval('var f'+i+' = str_rand();') } alert([f0,f1,f2,f3]);