pass a pointer to an array in a JS function

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

pass a pointer to an array in a JS function

Post by Burrito »

I am creating a function in JS that will loop over checkboxes and check them if necessary.

I have created a few arrays for the different sets of checkboxes above my function and I need to point to those arrays in one of my function arguments.

I know I"ve done this before but I can't remember where or how...here's an ex:

Code: Select all

var someArr = Array('one','two','three');
var someOtherArr = Array('four','five','six');
function checkAll(obj,whichArr)
{
   if(obj.checked)
   {
      for(i=0;i<whichArr.length;i++)
         //etc...
   }
}
unforutnately I can't pass the array variable itself in my function call because it's not defined at that point. I'm passing it as a string (the name of the array) and it's not flying.

I've also tried creating an associative multidimensional array and passing the name of the array I need to loop as the key of my array...still no go.

any ideas?

thx,

Burr
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

checkAll(someObj, someArr);
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

yeah I wish it were that easy, however, I need to be able to select which array I want to check all of the boxes dynamically.

I think I have it figured though.

I did end up using the multidimensional associative array.
Post Reply