String Methods tutorial in JavaScript

 <!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>String Methods JavaScript</title>
    <script>
        var str = "JavaScript is a GREAT and GREAT Language and it is widely used Language";
        var a = str.length;

        document.write(a + "<br><br>");
        var b = str.toLowerCase();
        document.write(b + "<br><br>");

        var u = str.toUpperCase();
        document.write(u + "<br><br>");

        var i = str.includes("GREAT");  //includes() function is a case sensitive function
        var i2 = str.includes("Great");
        var i3 = str.includes("iss");
        var i4 = str.includes("ipt");
        document.write(i + "<br>");
        document.write(i2 + "<br>");
        document.write(i3 + "<br>");
        document.write(i4 + "<br><br>");

        var s = str.startsWith("JavaScript"); //startsWith() function is a case sensitive function
        var s2 = str.startsWith("Javascript");
        var s3 = str.startsWith("Java");
        document.write(s + "<br>");
        document.write(s2 + "<br>");
        document.write(s3 + "<br><br>");

        var e = str.endsWith("Language");
        var e2 = str.endsWith("age");
        var e3 = str.endsWith("GREATE");
        document.write(e + "<br>");
        document.write(e2 + "<br>");
        document.write(e3 + "<br><br>");

        var c = str.search("is");
        var c2 = str.search("GREAT");
        var c3 = str.search("GREat");
        document.write(c + "<br>");
        document.write(c2 + "<br>");
        document.write(c3 + "<br><br>");

        var m = str.match(/GREAT/g);    //Here, "g" means Globally seach in given Whole String
        var m2 = str.match(/is/g);
        var m3 = str.match(/Language/g);
        document.write(m + "<br>");
        document.write(m2 + "<br>");
        document.write(m3 + "<br><br>");

        var j = str.indexOf("is");  //indexOf() function will return index of given word(Here, "is") of first position in whole above string
        document.write(j + "<br>");

        var j2 = str.lastIndexOf("is"); //lastIndexOf() function will return index of given word(Here, "is") of last position in whole string
        document.write(j2 + "<br><br>");

        var r = str.replace("JavaScript", "PHP");
        document.write(r + "<br>");
        var r2 = str.replace("is", "are");
        document.write(r2 + "<br>");
        var r3 = str.replace(/is/g, "are");
        document.write(r3 + "<br><br>");

        var strTwo = "      JavaScript      ";
        var a = strTwo.trim();
        alert(a);
    </script>
</head>

<body>
</body>

</html>



Comments

Popular posts from this blog

Generators tutorial in Advance JavaScript

Document Object Module DOM querySelector and querySelectorAll tutorial in JavaScript

Find Even and Odd Numbers with Loops tutorial in JavaScript