JavaScript Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Java-Script Tutorial
Introduction Introduction
Variables Variables
Operators Operators
Statements Statements
Loops Loops
Functions Functions
Objects Objects
Arrays Arrays
Cookies JS Cookies
Browser Objects Browser Objects
Form DOM Form DOM
Style Objects DOM Style Objects
Forums Ask Your Doubts
Scraps More about Javascript
Feedback Feedback
 




String Function - substring


Tutorials Javascript

Topic

how to get a portion of the string in javascript?



Explanation

Object: String

Method or Function: substring(integer, integer)

Description: Takes two integer arguments. The first argument is the start index and the second argument is the end index. This method returns a part or portion of the main string beginning from begin index to last index.


Example Code:
<script language=javascript>
var ss = " string test ";
var result = ss.substring(3,6);
document.write(result);
</script>

Result:

Explanation:
In the above example,
  • the main string is stored in a variable ss.
  • the method substring takes two arguments 3 and 6.
  • this method takes a portion of the string from the position 3 up to 6 and forms a new string. i.e "rin"
  • the result is of variable type string.





  • A Note
    Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

    Other Links

    web hosting