Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using array data as function name 1

Status
Not open for further replies.

dle46163

IS-IT--Management
Jul 9, 2004
81
US
Hi All,

I have a variable set like this:
var myVar = "slide_set1";

I have a working array which I'm pulling data out of. The array name is the same as the above variable. So, when I view the data in slot 0 of my array like this:
alert(slide_set1[0]);
my result is in fact the correct data.

However, without going into lots of explaination, I need to use the variable name (myVar) plus the array slot position together to create a dynamic function name. I've tried this:

this[myVar+"[0]"]();

with no luck... If I alert this:

alert (myVar+"[0]");

The result is literally slide_set1[0] and not the DATA in the POSITION of slide_set1[0]. I need to return the data in that position to use as a funcion name. Any thoughts would be great!









 
Try this:
Code:
alert(window[myVar][0]);

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top