- The original array is not affected by this method: a new one is created instead.
This JS slice function selects elements starting at the one indexed by start argument, and finishes at (but does not include) the element indexed by the end argument:
var carArray =['Mercedes-Benz', 'BMW', 'Audi']; var modelArray = carArray.slice(0, 2);
- Easy to use with a learn-by-doing approach
- Offers quality content
- Gamified in-browser coding experience
- The price matches the quality
- Suitable for learners ranging from beginner to advanced
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
Even though these arguments are optional, we predict that you will be using them to specify the starting index and the end of the collection process.
|start||Whole number used to specify initial index. Negative values can be used to select from end of an array. 0 by default.|
|end||Whole number used to specify last index for extraction (not included). If omitted, all element starting with the element specified by the start parameter are going to be selected. Negative values can be used to select from end of an array.|
Note: keep in mind that the first array element will have the index of 0, not 1.
|Return Value:||A new array which contains only the selected elements|