JavaScript Array slice() Method
JavaScript Array slice() Method
The slice()
method returns the selected elements (from start index to end index) in an array, as a new array object.
Note: This method does not alter the original array.
Default start index and end index
In the following example, we will omit both start index and end index, so that the JavaScript will assign the default value to both.
Example
Syntax
Parameter Values
Value | Type | Explanation |
---|---|---|
start | Optional | Specifies the starting index of an array to be selected. A negative index can be used to select the array elements in reverse order i.e., from right to left. If omitted, the default value is '0'. |
end | Optional | Specifies the ending index of an array to be selected. A negative index can be used to select the array elements in reverse order i.e., from right to left. If omitted, the default value is the 'length of an array'. |
Specific start index and Default end index
In the following example, we will specify the value for the start index and the browser will assign the default value for the end index.
Example
Specific start index and end index
In the following example, we will specify the value for both the start index and end index.
Example
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.