How to get substring from a string using jQuery

Topic: JavaScript / jQuery« Prev|Next »

Answer: Use the JavaScript substring() method

You can easily extract a substring out of a string using the JavaScript substring() method. The substring() method return substring based on the start (required) and end-position (optional) arguments. If end position is not specified it extracts the rest of the string.

  • <script type="text/javascript">
  • $(document).ready(function(){
  •     var myStr = "The quick brown fox jumps over the lazy dog";
  •     var subStr = myStr.substring(4, 20);
  •     alert(subStr);
  • });
  • </script>

Related FAQ

Here are some more FAQ related to this topic:


Your Feedback:


We would love to hear from you! Please say something.