Quick References
ADO
ASP
CSS2
HTML
JavaScript
Jet SQL
VBScript
WML
WMLScript
WSH
XHTML
XML DOM
XSLT
Features
Knowledge Base
Tutorials
Partners
ZVON.ORG
XML
Planet Source Code
VisualBuilder
Web Design
Your HTML Source
XML/XSLT Forums
ASPAlliance
Scripts
Programmers Heaven
Tek-Tips Forums
Developer Fusion
Code Project
All Objects
Array Object
METHOD: Array::slice
Array.
slice
(begin[,end])
The
slice
method creates a new array from a selected section of an array. The original array is unaffected by this but, if a string or number in one array is altered, it is not reflected in the other, whereas a change to a referenced object can be seen in both
Array
objects. The
slice
method uses the zero-based array index to determine the section out of which to create the new array. It extracts up to, but not including, the 'end' element (if no 'end' is specified, the default is the very last element). The following code creates an array called 'trees' and then displays a 'slice' of it:
Code:
trees = ["oak", "ash", "beech", "maple", "sycamore"]
document.write(trees.slice(1,4))
Output:
ash,beech,maple
If you use a negative index for the 'end', this specifies an element so many places from the end. Continuing with the above example, the following code would display the second through the third to last elements of the array:
Code:
trees = ["oak", "ash", "beech", "maple", "sycamore"]
document.write(trees.slice(1,-2))
Output:
ash,beech
Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information