add Array.prototype.lastIndexOf
This commit is contained in:
parent
68ff06af2a
commit
d8a88c7f47
1 changed files with 20 additions and 0 deletions
|
@ -58,6 +58,26 @@ if (!Array.prototype.indexOf) {
|
|||
};
|
||||
}
|
||||
|
||||
// see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
|
||||
if (!Array.prototype.lastIndexOf) {
|
||||
Array.prototype.lastIndexOf = function(val) {
|
||||
if (this === void 0 || this === null) {
|
||||
throw new TypeError();
|
||||
}
|
||||
var arr = Object(this),
|
||||
i,
|
||||
len = arr.length >>> 0,
|
||||
ret = -1;
|
||||
for (i = len - 1; i >= 0; i--) {
|
||||
if (i in arr && arr[i] === val) {
|
||||
ret = val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
// see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map
|
||||
if (!Array.prototype.map) {
|
||||
Array.prototype.map = function(fn, that) {
|
||||
|
|
Loading…
Reference in a new issue