Saturday, January 28, 2012

slice() Method


The slice() method extracts a part of a string and returns the extracted part in a new string.
 
Syntax: string.slice(begin,end);
 
JavaScript Code:
 
<script language="javascript" type="text/javascript">

    function sliceString() {
        var myName = new String('Anil Singh');
        alert(myName + '\n' + "After Slice=" + myName.slice(1, 5));
    }

</script>
 
HTML Code:
<button onclick="sliceString()">Slics Name here!!</button>

No comments: