get a string after a specific character js

In this example below you will see how to do a get a string after a specific character js with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by -Infamous, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright -Infamous ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>get a string after a specific character js</title>
  
  
  
  
  
</head>

<body>

  <p>Click the button to locate the last occurance of a specified value.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/-Infamous/get-a-string-after-a-specific-character-js-RyqGyb */
function myFunction() {
  var str = "Hello planet earth, you are a great - planet.";
  var n = str.lastIndexOf("-");
  var res = str.substr(n);
  document.getElementById("demo").innerHTML = res;
}

Comments