|
| JAVASCRIPT match() METHOD
The match() method searches a string for a specified match. If a match is found, it returns the match value else it returns null.
Please note that the match() method is case sensitive. The match() method takes the compulsory tosearchfor as it's argument.
The general format is:
string.match(tosearchfor);
Example:
<script type="text/javascript">
var string="Career Guidance";
document.write(string.match("reer"));
</script>
The above will output:
The match() method is extremely useful to test a string for a match and to perform different actions depending on whether the match was found or not as below:
<script type="text/javascript">
var string="Career Guidance";
if(string.match("reer"))
{
do this;
}
else
{
do that;
}
</script>
See Also:
|
|