JS polyfill for findLast
test : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast
implemented in chrome 97 : https://caniuse.com/mdn-javascript_builtins_array_findlast
// ==UserScript==
// @name Inject findLast Polyfill
// @version 0.0.1
// @match *://*/*
// @run-at document-start
// @grant none
// ==/UserScript==
if (!Array.prototype.findLast) {
Object.defineProperty(Array.prototype, "findLast",
{
value: function (predicate, thisArg) {
let idx = this.length - 1;
while (idx >= 0) {
const value = this[idx];
if (predicate.call(thisArg, value, idx, this)) {
return value;
}
idx--;
}
return undefined;
}
,
writable: true,
enumerable: false,
configurable: true
});
}