Use array.indexOf native function when available. p=arno, r=ahocevar
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9859 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -147,17 +147,21 @@ OpenLayers.Util.clearArray = function(array) {
|
||||
* obj - {Object}
|
||||
*
|
||||
* Returns:
|
||||
* {Integer} The index at, which the object was found in the array.
|
||||
* {Integer} The index at, which the first object was found in the array.
|
||||
* If not found, returns -1.
|
||||
*/
|
||||
OpenLayers.Util.indexOf = function(array, obj) {
|
||||
|
||||
for(var i=0, len=array.length; i<len; i++) {
|
||||
if (array[i] == obj) {
|
||||
return i;
|
||||
// use the build-in function if available.
|
||||
if (typeof array.indexOf == "function") {
|
||||
return array.indexOf(obj);
|
||||
} else {
|
||||
for (var i = 0, len = array.length; i < len; i++) {
|
||||
if (array[i] == obj) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user