String Object
indexOf()

The indexOf() method returns the position of value in the string(only first occurence). if value not found then return -1.

Example:-
<script type="text/javascript">
var str="test@gmail.com";
document.write(str.indexOf("@") + "<br />");
</script>

Output :-
4

match()

match method generally use in regular expression. this method search string if string find then this return string otherwise return null

Example :-
<script type="text/javascript">
var str1="This is email ID";
var str2=/email/;
document.write(str1.match(str2));
</script>

Output :-
email

toLowerCase()

This function convert string into lowercase string

<html>
<body>
<script language="javascript" type="text/javascript">
var str1="SHISHIR SHARMA";
var str2=str1.toLowerCase()
document.write(str2);
</script>
</body>
</html>

toUpperCase()

This function convert string into uppercase string

<html>
<body>
<script language="javascript" type="text/javascript">
var str1="shishir sharma";
var str2=str1.toUpperCase()
document.write(str2);
</script>
</body>
</html>

substr()

This function return extract characters from the string

<html>
<body>
<script language="javascript" type="text/javascript">
var str1="shishir sharma";
var str2=str1.substr(8,6)
document.write(str2);
</script>
</body>
</html>


Previous
Next