Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Scripting
 slice Method (Array)
Collapse All/Expand All Collapse All
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
 Collapse AllExpand All        Code: All Code: Multiple Code: Visual Basic Code: C# Code: Visual C++ Code: JScript 
slice Method (Array) (Windows Scripting - JScript)

Updated: March 2009

Returns a section of an array.

arrayObj.slice(start, [end]) 
arrayObj

Required. An Array object.

start

Required. The index to the beginning of the specified portion of arrayObj.

end

Optional. The index to the end of the specified portion of arrayObj.

The slice method returns an Array object containing the specified portion of arrayObj.

The slice method copies up to, but not including, the element indicated by end. If start is negative, it is treated as length + start where length is the length of the array. If end is negative, it is treated as length + end where length is the length of the array. If end is omitted, extraction continues to the end of arrayObj. If end occurs before start, no elements are copied to the new array.

The following examples illustrate the use of the slice method. In the first example, all but the last element of myArray is copied into newArray. In the second example, only the last two elements of myArray are copied into newArray.

newArray = myArray.slice(0, -1)
newArray = myArray.slice(-2)

Date

History

Reason

March 2009

Added a second example.

Information enhancement.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker