JavaScript slice() Method
Complete Array Object Reference
Definition and Usage
The slice() method returns selected elements from an existing array.
Syntax
arrayObject.slice(start,end)
|
| Parameter |
Description |
| start |
Required. Specify where to start the selection. Must
be a number |
| end |
Optional. Specify where to end the selection. Must
be a number |
Tips and Notes
Tip: You can use negative numbers to select from the end of the array.
Note: If end is not specified, slice() selects all elements from the
specified start position and to the end of the array.
Example 1
In this example we will create an array, and then display selected elements from
it:
<script type="text/javascript">
var arr = new Array(3);
arr[0] = "Jani";
arr[1] = "Hege";
arr[2] = "Stale";
document.write(arr + "<br />");
document.write(arr.slice(1) + "<br />");
document.write(arr);
</script>
|
The output of the code above will be:
Jani,Hege,Stale
Hege,Stale
Jani,Hege,Stale
|
Example 2
In this example we will create an array, and then display selected elements from
it:
<script type="text/javascript">
var arr = new Array(6);
arr[0] = "Jani";
arr[1] = "Hege";
arr[2] = "Stale";
arr[3] = "Kai Jim";
arr[4] = "Borge";
arr[5] = "Tove";
document.write(arr + "<br />");
document.write(arr.slice(2,4) + "<br />");
document.write(arr);
</script>
|
The output of the code above will be:
Jani,Hege,Stale,Kai Jim,Borge,Tove
Stale,Kai Jim
Jani,Hege,Stale,Kai Jim,Borge,Tove
|
Try-It-Yourself Demos
slice()
How to use slice() to display selected elements from an existing array.
Complete Array Object Reference
 |
 |
 |
 |
|
The Ektron Intranet
lets you do everything you need to do on your corporate intranet and everything you want to do... all with just one application.
What can you do with the Ektron Intranet? |
 |
Navigate through content, documents, assets, colleagues and workgroups quickly and intuitively with enterprise search |
 |
Communicate with friends and colleagues with forums, message boards and corporate blogging using the new Social Networking Platform |

|
Utilize the extensive out-of-the box features or customize your site through Ektron CMS400.NET's open architecture |
 |
Promote collaboration in your organization through project workspaces where others can efficiently find information and work together |
 |
Author/edit content, manage navigation, menus, audit trails, workflow and approvals with the best in breed Content Management |
|
|
|
|
See why there are 20,000+ Ektron integrations worldwide.
|
|
 |
TAKE THE VIDEO TOUR |
 |
or download a FREE TRIAL today. |
|