Selecting elements within nested arrays
<p>I'm trying to traverse through nested array var, and select those array elements which satisfy a single condition. I'm trying to select all the first element ("choice1, choice2...") of an inner array only when the "selectedIndex" is found in "el".<br>
For instance: if "opt2" is selected from the drop-down, it should NOT select element "choice2" and "choice4" as there are not '2' that array, but it should get all other (choice1, choice3, choice5). Click <a href="http://jsfiddle.net/dQgFj/3/" rel="nofollow">here</a> for demo.
Many thanks in advance.</p>

<pre><code>var all_data = new Array(
   new Array("selection1", new Array(
      new Array("choice1", new Array('a', [1, 2, 3, 4]), new Array('b', [3, 4])),
      new Array("choice2", new Array('a', [3, 4]), new Array('b', [1, 4]), new Array('c', [1, 3, 4]))
   )),
   new Array("selection2", new Array(
      new Array("choice3", new Array('a', [2, 4]), new Array('b', [1, 3, 4]), new Array('c', [3, 4])),
      new Array("choice4", new Array('b', [1, 4]), new Array('c', [1, 3])),
      new Array("choice5", new Array('b', [1, 2, 4]), new Array('c', [1, 2, 3, 4]))
   ))
);

function arraySearch(arr, i) {
  var result = [];
  for (var i = 0; i &lt; arr.length; i++) {
     for (var j = 0; j &lt; arr[i].length; j++) {
         for (var k = 0; k &lt; arr[i][j].length; k++) {
            var el = arr[i][j][k];
            if (el instanceof Array) { 
               //alert(el);
               //here i want to check if 'i' exists in each 'el'
               //and if found, concat the element "choice1, choice2..." 
             }
         }
     }
  }
  return result;
}
function getChoices(){
    selected_method = document.form.method.selectedIndex;
    var n = selected_method+1;
    var elements = arraySearch(all_data, n);
    //alert(elements);
}    
    &lt;select name="method" onchange="getChoices();"&gt;
       &lt;option&gt;opt1&lt;/option&gt;
       &lt;option&gt;opt2&lt;/option&gt;
       &lt;option&gt;opt3&lt;/option&gt;
       &lt;option&gt;opt4&lt;/option&gt;
    &lt;/select&gt;
</code></pre>
