Methods

STRING METHODS

<!DOCTYPE html>

<html>

<head>

<style>

table, td, th {

  border: 1px solid black;

}


table {

  border-collapse: collapse;

  width: 100%;

}


td {

  height: 50px;

  vertical-align: bottom;

}

</style>

</head>

<body>


<h2>JavaScript Methods</h2>

<table>


    <tr>

<td>

<label id="">String Methods</label>

</td>

        <td>

            

        </td>

</tr>

<tr>

<td>

<label id="">Length method to find the length of the text</label>

</td>

        <td>

            <label id="lblString"></label>

        </td>

</tr>

    <tr>

<td>

<label id=""># IndexOf() method is used to find the position of first occurrence of a text that you are looking for. <br><br> # If index is not found, -1 will be returned. <br><br> # Search() method is used to find the position of the first time the text occur in the string that we are searching for. <br><br> #Slice() method is used to extract the part of the string.</label>

</td>

        <td>

            <label id="lblIndex"></label>

        </td>

</tr>

   

</table>


<script>


var x = "Thisisalongstring";

document.getElementById("lblString").innerHTML = x.length;


var x = "We are learning IndexOf method of the string method";

var y = x.indexOf("method");

var z = x.lastIndexOf("method");

var a = x.indexOf("test");

var b = x.search("method");

var c = x.slice(7, 15);


document.getElementById("lblIndex").innerHTML = 

"Index of 'method' is:" + y + " <br> " +" <br> " + "Last Index of 'method' is: "+ z +" <br> " + " <br> " + "Index of 'test' is not found: " + a + " <br> " +" <br> " + "Using 'search' to find index: " + b + " <br> " +" <br> "+ "Slice out 'learning' from the sentence above: " + c ;


</script>


</body>

</html> 

No comments:

Post a Comment

Date Object

Purple: Style Blue: HTML Green: JavaScript  <!DOCTYPE html> <html> <style> #dates {   font-family: "Trebuchet MS...