VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-initial-function/

⇱ Lodash _.initial() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.initial() Function

Last Updated : 2 Sep, 2024

Lodash _.initial() function is used to get all elements of the array in the range 0 to n-2. Thereby getting all elements except the (n-1)th element.

Syntax:

Lodash.initial(arrayObject);

Parameters:

  • arrayObject: There is only one parameter of type array.

Return Value:

  • It returns an array object.

Example 1: In this example, When an array of objects is given we are getting all the elements of that array but not the last one because of the use of the lodash _.initial() function.

Output:

👁 Image


Example 2: In this example, we are getting all the elements of that array but not the last one because of the use of the lodash _.initial() function.

Output:

👁 Image

Example 3: In this example, we are getting empty array beacuse the original array has only one element.

Output:

👁 Image
Comment