Calling a function based on a string

So I have a string which I want to use to call a function. How can I do this?. For example lets say I have a string = “function1”. Now since I have this string I to use it to call

function function1();

to execute it within my application. Note that sometimes I may have a string which will be arguments to call another function for example, string = function2,1,2. This will call

function function2(1,2)

. Any idea on how I can do this?

You can use windowstring; like the example below:

function test() {
	alert('Function called!');

var str = 'test';

In this case you will need to split() the string into an array of its components. The first element of the array will be the function name and the other elements will be the arguments. Insert the argument elements in the () of


excellent these responses work perfectly thanks alot