Slice in string:- Genius student


    The slice() method extracts parts of a string and returns the extracted parts in a new string.
    Use the start and end parameters to specify the part of the string you want to extract.
    The first character has the position 0, the second has position 1, and so on.
    Use a negative number to select from the end of the string.

Code:-


<html>

<head>
 <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

 <h1>slice() in string</h1>

 <input type="button" onclick="fun1();" value="slice(1)">
 <input type="button" onclick="fun2();" value="slice(3,6)">

 <script>
  var cntry = "Tamilnadu";

  function fun1()
  {
   alert("Actual : " + cntry);
   alert(cntry.slice(1)); //return excluding 1st value  (Not removed)
  }

  function fun2()
  {
   alert("Actual : " + cntry); //return 3 to 6th character
   alert(cntry.slice(3, 6));
  }
 </script>

</body>

</html>
Slice in string:- Genius student Slice in string:- Genius student Reviewed by Network security on October 06, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.