Copyright © tutorialspoint.com

Javascript Array slice() Method

previous next

Advertisements


Description:

Javascript array slice() method extracts a section of an array and returns a new array.

Syntax:

array.slice( begin [,end] );

Here is the detail of parameters:

Return Value:

Returns the extracted array based on the passed parameters.

Example:

<html>
<head>
<title>JavaScript Array slice Method</title>
</head>
<body>
<script type="text/javascript">
var arr = ["orange", "mango", "banana", "sugar", "tea"];
document.write("arr.slice( 1, 2) : " + arr.slice( 1, 2) ); 
document.write("<br />arr.slice( 1, 3) : " + arr.slice( 1, 3) ); 
</script>
</body>
</html>

This will produce following result:

arr.slice( 1, 2) : mango
arr.slice( 1, 3) : mango,banana 

To understand it in better way you can Try it yourself.


previous next

Copyright © tutorialspoint.com