VOOZH about

URL: https://www.geeksforgeeks.org/node-js/lodash-_-slice-function/

⇱ Lodash _.slice() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.slice() Function

Last Updated : 2 Sep, 2024

Lodash _.slice() function is used to take a slice of the array from the starting index to the end index here end index is exclusive and the start index is inclusive.

Syntax:

_.slice(array, startIndex, endIndex);

Parameters:

  • array: It is the array from which the slice is to be taken.
  • startIndex: It is the starting index from which slicing of the array starts.
  • endIndex: It is the end Index to which slicing is done. Please note that endIndex is exclusive.

Return Value:

  • It returns the slice of the array and the return type is array.

Example 1: In this example, we are slicing an array and the given index size is in the range of the array size.

Output:

👁 Image


Example 2: In this example, we are slicing an array and the given end index is not in range of the size of the array.

Output:

👁 Image


Example 3: In this example, we are slicing the empty array.

Output:

👁 Image

Examples 4: In this example, we are slicing an array where start and end index are not given. 

Output:

👁 Image
Comment
Article Tags:

Explore