js
str.lastIndexOf(search, fromIndex?)الـfromIndex هنا هو أقصى index ممكن يبدأ منه الظهور، والبحث بيمشي ناحية البداية. -1 لو مفيش.
البرهان
js
const s = 'banana';
console.log(s.lastIndexOf('an'));
console.log(s.lastIndexOf('an', 2));
console.log(s.lastIndexOf('x'));
const path = 'a/b/c.txt';
console.log(path.slice(path.lastIndexOf('/') + 1));النتيجة
3 1 -1 c.txt