slice()

The slice() method is used to return the characters which are between numberOne and numberTwo (see syntax). Keep in mind that the numbers given must include the number zero as the starting point of the string - the index of the characters is zero based. numberOne cannot be a negative number. If numberTwo is negative, the character places are counted from the end of the string, moving toward the beginning (counting starts at the left, moving toward the right). If only one value is stated as the parameter, the value returned will be the character starting at the given position followed by the rest of the string.

syntax:

string.slice(numberOne, numberTwo)

string.slice(number)

EXAMPLE

textString = new String("This is the text to be returned");

document.write(textString.slice(4) );

The example begins with the creation of a string called textString. The document.write statement then writes the content of textString to the screen starting at character 4. The output should look like the following:



is the text to be returned