Answers for "how to find last occurrence of a character in a string in javascript"

7

javascript get last n characters of string

'abc'.slice(-1); // c
Posted by: Guest on February-03-2020
2

js last index of

const str = "Users/Edit/12345";
let idx = str.lastIndexOf("/"); // returns 10
idx = str.lastIndexOf("x"); // returns -1

idx = str.lastIndexOf("Edit") // returns 6
idx = str.lastIndexOf("edit") // returns -1 -- case sensitive

// add "from" parameter
// the search happens backwards, starting at the provided from parameter
idx = str.lastIndexOf("s"); // returns 4
idx = str.lastIndexOf("s", 3); // returns 1
Posted by: Guest on August-31-2020
1

lastindexof js

string.lastIndexOf("subString")
Posted by: Guest on May-02-2020
0

find the last occurrence of a character in a string javascript

str.lastIndexOf(searchValue[, fromIndex])
Posted by: Guest on March-19-2021

Code answers related to "how to find last occurrence of a character in a string in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language