VOOZH about

URL: https://www.geeksforgeeks.org/javascript/collect-js-last-method/

⇱ Collect.js last() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js last() Method

Last Updated : 27 Nov, 2020

The last() method is used to return the last element from the collection that satisfy the given truth test.

Syntax:

collect(array).last(callback)

Parameters: The collect() method takes one argument that is converted into the collection and then last() method is applied on it. The last() method holds the callback function.

Return Value: This method returns the last element from the collection that satisfy the given truth test.

Below example illustrate the last() method in collect.js:

Example 1:

Output:

50

Example 2:

Output:

{ name: 'Rahul', dob: '19-08-96', section: 'B', score: 77 }
Comment
Article Tags: