Dynamic Javascript Variables

January 4th, 2009 | Posted in jQuery
1

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

Related posts

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