String.slice() : slice : String JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » String » slice »

 

String.slice()












Syntax








string.slice(num1, num2)
    string.slice(num)



The slice() method returns the characters between the indexed positions num1 and num2.

The first character is in position 0.

If num2 is a negative number, the string counts from the end of the string to end the slice.

If passing a single index, the method will return all characters until the end of the string.












<html>
    <script language="JavaScript">
    <!--
    var myString = new String("This is a test");

    var mySlice = myString.slice(0,6);

    document.write('The first characters of our string, ' + myString);
    document.write(', are: ' + mySlice);
    document.close();

    -->
    </script>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo String
» slice