Javascript language

adplus-dvertising
slice() Method
Previous Home Next

The slice() method extracts a part of a string and returns the extracted part in a new string.

Syntax:

string.slice(begin,end)

Example:

<html>
<body>
<script>
function slice_string()
{
var myName = new String('Aditya Tiwari'); 
   alert(myName+'\n'+"After Slice="+ myName.slice(1,6));
}
</script>
<button onclick="slice_string()">Slice of Name</button>
</body>
</html>

Output:

Previous Home Next