add indexOf() function to array - returns first index of a given element in an array. useful for testing, etc

git-svn-id: http://svn.openlayers.org/trunk/openlayers@225 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-05-21 14:42:18 +00:00
parent d87992649f
commit d694efa60e
2 changed files with 23 additions and 2 deletions

View File

@@ -519,7 +519,22 @@ Array.prototype.clear = function() {
this.length = 0;
};
/**
* @param {Object} element
*
* @returns The first index of the element in the array if found. Else returns -1
* @type int
*/
Array.prototype.indexOf = function(element) {
var index = -1;
for(var i=0; i < this.length; i++) {
if (this[i] == element) {
index = i;
break;
}
}
return index;
}
/**
* zIndex is NOT set