js find last occurrence in string code example
Example 1: javascript remove last character from string
var str = "Hello";
var newString = str.substring(0, str.length - 1);
Example 2: js last index of
const str = "Users/Edit/12345";
let idx = str.lastIndexOf("/");
idx = str.lastIndexOf("x");
idx = str.lastIndexOf("Edit")
idx = str.lastIndexOf("edit")
idx = str.lastIndexOf("s");
idx = str.lastIndexOf("s", 3);
Example 3: javascript get last word in string
function lastWord(words) {
let n = words.replace(/[\[\]?.,\/
return n[n.length - 1];
}
Example 4: find the last occurrence of a character in a string javascript
str.lastIndexOf(searchValue[, fromIndex])