Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
76
rated 0 times [  82] [ 6]  / answers: 1 / hits: 18618  / 15 Years ago, thu, june 4, 2009, 12:00:00

I have several arrays in Javascripts, e.g.



a_array[0] = abc;

b_array[0] = bcd;

c_array[0] = cde;



I have a function which takes the array name.



function perform(array_name){
array_name = eval(array_name);
alert(array_name[0]);
}
perform(a_array);
perform(b_array);
perform(c_array);


Currently, I use eval() to do what I want.

Is there any method not to use eval() here?


More From » javascript

 Answers
45

You can either pass the array itself:



function perform(array) {
alert(array[0]);
}
perform(a_array);


Or access it over this:



function perform(array_name) {
alert(this[array_name][0]);
}
perform('a_array');

[#99377] Tuesday, June 2, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nicole

Total Points: 648
Total Questions: 95
Total Answers: 103

Location: Turks and Caicos Islands
Member since Sun, Mar 7, 2021
3 Years ago
nicole questions
Mon, Mar 22, 21, 00:00, 3 Years ago
Thu, Jan 23, 20, 00:00, 4 Years ago
Wed, Nov 27, 19, 00:00, 5 Years ago
Fri, May 17, 19, 00:00, 5 Years ago
;