Strings

charAt(), includes() and indexOf()
    <!DOCTYPE html>
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title>String Methods Part 1</title>
        <script>
            window.onload = function () {
                var myString = "the quick brown fox jumped over the lazy dogs";
                for (var x = 0; x < myString.length; x++) {
                    console.log(myString.charAt(x));
                }
                var n = myString.includes('x');
                console.log(x);
                var z = myString.indexOf('x');
                console.log("The x is at index " + z);
          }
        </script>
    </head>
    <body>
        <div id="result"></div>
    </body>
    </html>
        
Top

Index

search() and replace()
    <!DOCTYPE html>
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title>String Methods Part 2</title>
        <script>
            var myString = "Four score and seven years ago";
            var n = myString.search("seven");
            console.log(n);

            var newString = myString.replace("Four", "Six");
            console.log(myString);
            console.log(newString);
        </script>
    </head>
    <body>
    </body>
    </html>
        
Top

Index

slice(), split(), and substr()
    <!DOCTYPE html>
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title>String Methods Part 3</title>
        <script>
            var myString = "If you are strong enough, there are no precedents";
            var newString = myString.slice(0, 15);
            console.log(newString);

            var csv = "mark,Joan,Rick,Kerri,Connor,Colleen";
            var names = csv.split(',');
            console.log(names);

            var theString = "Hello World!";
            console.log(theString.substr(1, 4));
        </script>
    </head>
    <body>
    </body>
    </html>
        
Top

Index

n4jvp.com