Dynamic Javascript Variables

To create dynamic variables in JavaScript use the eval() function. Of course eval() can be for other dynamic JavaScript creation as well.

function dynamic(id)
{
	// Create dynamic variable and set the value
	eval("var test_" + id + " = \"value goes here\";");

	// Return the value
	return eval("test_" + id);
}

// Call function
var test = dynamic(123);

// Display the value
document.write(test);

Demo

View a demo here

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Related Posts

Tags: ,

Comments (1)

  1. rohan crone says:

    You do not need any skills and more necessary rohan crone for a regular attack, but it still looks like you are using a skill.

Leave a Reply





Donate

If you found this article useful and would like to see more like it this please consider making a donation.