I thought I tried using this technique once for an array of objects that had multiple properties... and it didn't work. It would only work if my array was that of strings or numbers.
It also works for objects - but (!) note that objects are compared by reference (i.e. its not a deep search, but just a comparison of their pointers). So...
JavaScript
var a = [{ id : 1, name : 'Name' }, { id : 1, name : 'Name' }];
//a has only "unique" elementsvar obj = { id : 1, name : 'Name' };
var b = [obj, obj];
//b has only 1 unique element
However, it should be noted that in such cases you can use JavaScript's sort function (Array.prototype.sort). Here you could specify your own comparer, which could be used to manipulate some other array (captured by a closure) in a custom way and more detail.
Last Visit: 31-Dec-99 18:00 Last Update: 24-Jun-24 8:23