Jquery Substring Example - Jquery

How to use substring method in jquery?

Snippet Code


  
Rate this page :
  [ 0 votes]

This substring method is used to extract the characters from string. Jquery substring() method takes two parameters like substring (from, to).
From parameter is required which is known as the index where to start the substring. Here the index starts with 0.
To parameter is optional which is known as the index where to stop. If it is not passed then rest of the string will be extracted

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(document).ready(function(){ var str = 'Hscripts Snippets'; $('#originalstring').html(str); $('#substring').html(str.substring(2,12)); }); </script> <b>String :</b> <span id='originalstring'> </span> </br></br> <b>Substring :</b> <span id='substring'> </span>

Tags


Ask Questions

Ask Question