All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

JavaScript Substring After Character

Last Updated : Mar 11, 2024

JavaScript Substring After Character

In this tutorial we will show you the solution of JavaScript substring after character, today we understand how to get the substring after a specific or special character.

This method is same like MySQL like method in which we get full row or specific data from columns using _o%.

Hence, this is used to get the data in which second character is o. We use this same method with different way inside JavaScript. Let us understand this with help of codes.

Step By Step Guide On JavaScript Substring After Character :-

As, there are many methods with the help of which we are able to get substring after character.

In this article, we are going to use substing() method. So, let us understand how to use substring method with help of codes.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title> JavaScript substring after character </title>
</head>
<body>
  <script>
  const string = 'A string is_given here known as string';
  const after = string.substring(str.indexOf('_') + 1);
  console.log(after);
</script>
</body>
</html>
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
  4. Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
  5. Here, we show you how to get substring after character using JavaScript.
  6. For this inside body tag, we create a variable named string. And inside this we create or say write string and use a special character here that is _ as you see in codes given above.
  7. Now, after this we want that we have to get the substring after character _. So, the content that we get on output is given here known as string.
  8. So, for this we use substring() on string and store this is variable named after that is created with the help of const.
  9. Now, at last we print the output using console. It means that the output should not be printed on screen it goes showed on when we inspect our webpage and opens console tab.
  10. At last, the <body> and <html> tags are closed with </body> and </html> respectively.

Conclusion :-

At last in conclusion, here we can say that with the help of this article able to understand how to get substring after character using JavaScript.

I hope this tutorial on JavaScript substring after character helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Anjali

Experienced Computer Programmer with a broad range of experience in technology. Strengths in application development and Object Oriented architecture design, front end programming, usability and multimedia technology. Expert in coding languages such as C, C++ Java, JavaScript, PHP and more.

Follow Anjali On Linkedin 🡪