Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found that in IE6 at least (I'm not sure about the more recent versions), the built-in Array type didn't have an indexOf method. If you're testing in IE, perhaps that's why you couldn't get started. I wrote this little addition to include in all my code:</p> <pre><code>if(!Array.prototype.indexOf){ Array.prototype.indexOf = function(obj){ for(var i=0; i&lt;this.length; i++){ if(this[i]===obj){ return i; } } return -1; }; } </code></pre> <p>I can't really take credit for this. It's probably a fairly generic piece of code I found in some tutorial or one of Doug Crockford's articles. I'm quite sure someone will come along with a better way of writing it.</p> <p>I find working in Firefox is a good place to start because you can install the Firebug console and get a better idea where things are going wrong. I admit that doesn't solve cross-browser problems, but at least it allows you to get a start on your project.</p> <p>This little piece of code will ensure you can use the indexOf method to find where a given value is in a one-dimensional array. With your 2-dimensional array, each element in the outer array is an array not a single value. I'm going to do a little test to see exactly how that works and get back to you, unless someone else comes in with a better answer. </p> <p>I hope this at least gets you started.</p> <p>UPDATE Assuming you have a browser that implements Array.indexOf, I've tried every which way to pass one of the array elements in your outer array. </p> <pre><code>alert(array.indexOf([3,56])) alert(array.indexOf("3,56")) </code></pre> <p>just return -1.</p> <p>Oddly,</p> <pre><code>alert(array.indexOf(array[1])) </code></pre> <p>correctly returns 1. But you need to know the index of the inner array to get the index! I can't see a way of passing an array to the indexOf method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload