jQuery.inArray should not return -1 when matching nested arrays
|Reported by:||gabriel||Owned by:|
|Keywords:||inArray, arrays, utility||Cc:||gabriel|
So if I'm trying to find if an array is a member of a dataset, jQuery.inArray will always return -1, which is not the right behaviour.
I've written a patch that solves this problem. With my patch, the following works:
var a = [1, 2]; var b = ["x", true, 7, a]; var c = [[0, 1], [1, 2], [2, 3]]; jQuery.inArray(a, b); //=> returns 3 jQuery.inArray(a, c); //=> returns 1
This patch also includes a new public utility method, jQuery.compareArrays, which can be used to check if two arrays are the same. I opted for making this a publicly-accessible method since it could be useful to others in their code and not just within jQuery.
Also, if there's a better way of checking if a variable is an Array (without having to write a whole bunch of extra code), please feel free to amend my patch. :)