JAVASCRIPT

 Home  Computers & Internet  Web Programming JAVASCRIPT
What is Javascript?
Javascript Placement
Syntax
Reserved Words
Variables
Data Types
Escaping Characters
Concatenation
Arithmetic Operators
Assignment Operators
Comparison Operators
Boolean Operators
Conditional Operator
If Statements
Else If Statements
If Else Statements
Switch Statements
While Loops
For Loops
Do While Loops
Break Statement
Continue Statement
prompt()
alert()
Date()
Event Handlers
String Object Methods
Math Object Methods
Window Object Methods
Arrays

JAVASCRIPT slice() METHOD

The slice() method extracts a chunk of a string between positions you specify and returns that chunk as a new string.

The general format is:

string.slice(startposition, endposition);

The startposition specifies what position to start extracting from, endposition specifies what position to stop extracting from ie. the extracted part will be from startposition inclusive to endposition exclusive. The endposition argument is optional and if it is not specified, then extraction will be from startposition to end of string.

Also remember that the first position of a string is always 0 and not 1.

Example: No endposition specified

<script type="text/javascript">

var string="The brown box is brown";

document.write(string.slice());

</script>

The above will output:



Example: endposition Specified

<script type="text/javascript">

var string="The brown box is brown";

document.write(string.slice(4, 9));

</script>

The above will output:





See Also:

anchor() big()
blink() bold()
charAt() charCodeAt()
concat() fixed()
fontcolor() fontsize()
fromCharCode() indexOf ()
italics () lastIndexOf()
link() match()
replace () search()
slice() small()
split() strike()
sub() substr()
substring() sup()
toLowerCase() toUpperCase()
toSource() valueOf ()

Home | Privacy Policy | Terms Of Use | Contact Us