JavaScript String Functions
In this lesson you will learn JavaScript string function. You can perform different operation. If you want to count the string length use str.length function. Also String is transfer to uppercase or lowercase and change the style of string and more string functions.
JavaScript count the length of a string
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript str length function</title>
</head>
<body>
<script type="text/javascript">
var str = "Hello String!";
document.write('Length of the given String: ' + str.length);
</script>
</body>
</html>
Example Result
JavaScript string toLowerCase() and toUpperCase()
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript String toLowerCase() and toUpperCase() function</title>
</head>
<body>
<script type="text/javascript">
var str = "Hello String";
document.write(str.toUpperCase() + "<br />");
document.write(str.toLowerCase());
</script>
</body>
</html>
Example Result
JavaScript String Format functions
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript string function</title>
</head>
<body>
<script type="text/javascript">
var str = "Hello String!";
document.write("<p> Bold: " + str.bold() + "</p>");
document.write("<p> Italic: " + str.italics() + "</p>");
document.write("<p> Big: " + str.big() + "</p>");
document.write("<p> Small: " + str.small() + "</p>");
document.write("<p> Strike: " + str.strike() + "</p>");
document.write("<p> Fontsize: " + str.fontsize(4) + "</p>");
document.write("<p> Fontcolor: " + str.fontcolor("orange") + "</p>");
document.write("<p> Link:"+str.link("http://Way2Tutorial.com")+"</p>");
document.write("<p> Subscript: " + str.sub() + "</p>");
document.write("<p> Superscript: " + str.sup() + "</p>");
</script>
</body>
</html>
Example Result