inArray() Help!

inArray() Help!

I need to pass a variable that represents another variable (in this case an array), is there any way of doing this?

The first set of arrays (arr1 - arr6) are directly associated with the 6 links and will be created dynamically by the database to set which divs are related to which parent links. When the parent link is clicked I'd ideally like it to run through all of the divs (in .testcontet) and determine (based on their index) which ones are in the array. 

Does anyone know an easy solution?

  1. <script type="text/javascript">
  2. $(document).ready(function(){
  3. var arr1 = [ 1, 2, 8 ];
  4. var arr2 = [ 4, 5, 8 ];
  5. var arr3 = [ 1, 2, 3 ];
  6. var arr4 = [ 3, 2, 8 ];
  7. var arr5 = [ 1, 2, 8 ];
  8. var arr6 = [ 5, 6, 7 ];
  9. $('.testnav a').click(function(){
  10. var index = $(this).index('.testnav a') + 1;
  11. var thisarray = 'arr' + index;
  12. var thisclass = $(this).attr('class');
  13. $('.testcontent div').each(function() {
  14. var thisindex = $(this).index('.testcontent div') + 1;
  15. if (jQuery.inArray(thisindex, thisarray) != '-1') { alert(thisindex); }
  16. });
  17. return false;
  18. });
  19. });
  20. </script>
  21. <div class="testnav">
  22. <a href="">Parent 1</a><br />
  23. <a href="">Parent 2</a><br />
  24. <a href="">Parent 3</a><br />
  25. <a href="">Parent 4</a><br />
  26. <a href="">Parent 5</a><br />
  27. <a href="">Parent 6</a><br />
  28. </div>
  29. <div class="testcontent">
  30. <div class="test1">Test 1</div>
  31. <div class="test2">Test 2</div>
  32. <div class="test3">Test 3</div>
  33. <div class="test4">Test 4</div>
  34. <div class="test5">Test 5</div>
  35. <div class="test6">Test 6</div>
  36. <div class="test7">Test 7</div>
  37. <div class="test8">Test 8</div>
  38. </div>

if you replace 
  1. if (jQuery.inArray(thisindex, thisarray) != '-1') { alert(thisindex); }
with 
  1. if (jQuery.inArray(thisindex, arr1) != '-1') { alert(thisindex); }
and then click any of the links, you'll see what I'm ultimately trying to accomplish.