Array.prototype.find
Find a string or regexp in a array.
See source for the example code and below for correct code.
03-01-2007Code for Array Find
// Find in array (position);
// e.g.: testArray.find("test");
// e.g.: testArray.find(/^blue/i);
// return: [integer or boolean] returns position or if not excised false;
// syntax: Array [object Array] array used to search in;
// str [string or regexp] value to look for, can be string or regexp;
Array.prototype.find = function(str) {
var returnArray = false;
for (i=0; i < this.length; i++) {
if (typeof(str) == 'function') {
if (str.test(this[i])) {
if (!returnArray) {
returnArray = [];
}
returnArray.push(i);
}
}
else {
if (this[i]===str) {
if (!returnArray) {
returnArray = [];
}
returnArray.push(i);
}
}
}
return returnArray;
};
Array Find v1
This text should not be seen and spoken.