js split last occurrence code example

Example 1: javascript get last character in string

var hello = "Hello World";
var lastCharOfHello=hello.slice(-1);//d

Example 2: js split last occurence

var lastIndex = src.lastIndexOf('.');

  // Add the string before the last .
  // Return updated string, this will update the src attribute value
  return src.substr(0, lastIndex) + '-fx' + src.substr(lastIndex);

Example 3: js remove last character

let str = "12345.00";
str = str.substring(0, str.length - 1);
console.log(str);