You are here: irt.org | FAQ | JavaScript | Text | Q1749 [ previous next ]
You can use the eval() function to evaluate expressions at run time:
<html> <head> <script language="JavaScript"><!-- var str1, str2, str3, str4, str5; function myFunction() { var somestring = 'abc/def/ghi/jkl/mno'; var splitArray = somestring.split('/'); for (var i=0; i<splitArray.length; i++) { eval('str' + (i+1) + '="' + splitArray[i] + '"'); } } myFunction(); alert(str1 + '\n' + str2 + '\n' + str3 + '\n' + str4 + '\n' + str5); //--></script> </head> <body> ... </body> </html>