JavaScript Array slice() methodThe JavaScript array slice() method extracts the part of the given array and returns it. This method doesn't change the original array. SyntaxThe slice() method is represented by the following syntax: Parameterstart - It is optional. It represents the index from where the method starts to extract the elements. end - It is optional. It represents the index at where the method stops extracting elements. ReturnA new array contains the extracted elements. JavaScript Array slice() method exampleHere, we will understand slice() method through various examples. Example 1Let's see a simple example to extract an element from the given array. Test it NowOutput: Node.js Example 2Let's see one more example to extract various element from the given array. Test it NowOutput: AngularJS,Node.js,JQuery Example 3In this example, we will provide the negative values as index to extract elements. Test it NowOutput: AngularJS,Node.js,JQuery
Next TopicJavaScript Array
|