Collect.js last() Method Last Updated : 27 Nov, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: javascript const collect = require('collect.js'); const collection = collect([10, 20, 30, 40, 50]); const last_val = collection.last(element => element / 10); console.log(last_val); Output: 50 Example 2: javascript const collect = require('collect.js'); let obj = [ { name: 'Rahul', dob: '25-10-96', section: 'A', score: 98, }, { name: 'Aditya', dob: '25-10-96', section: 'B', score: 96, }, { name: 'Abhishek', dob: '16-08-94', section: 'A', score: 80 }, { name: 'Rahul', dob: '19-08-96', section: 'B', score: 77, }, ]; const collection = collect(obj); const last_val = collection.last( element => element.name == 'Rahul'); console.log(last_val); Output: { name: 'Rahul', dob: '19-08-96', section: 'B', score: 77 } Comment More infoAdvertise with us Next Article Collect.js last() Method A ashokjaiswal Follow Improve Article Tags : JavaScript Web Technologies Collect.js Similar Reads Collect.js max() Method The max() method is used to return the maximum value of a given key. It takes a collection and returns the maximum values present in that collection for a given key. Syntax: collect(array).max(key)Parameters: The collect() method takes one argument that is converted into the collection and then the 2 min read Collect.js keys() Method The keys() method is used to return all of the collection's keys. Syntax: collect(array).keys() Parameters: The collect() method takes one argument that is converted into the collection and then keys() method is applied on it. Return Value: This method returns the collection keys. Below example illu 1 min read Collect.js mapInto() Method The mapInto() method is used to iterate through the collection elements and instantiate the given class with each element as a constructor. Syntax: collect(array).mapInto() Parameters: The collect() method takes one argument that is converted into the collection and then mapInto() method is applied 2 min read Collect.js mapSpread() Method The mapSpread() method is used to iterate over the given collection items and pass each nested collection item value into the given callback. Syntax: collect(array).mapSpread(callback) Parameters: The collect() method takes one argument that is converted into the collection and then mapSpread() meth 1 min read Collect.js keyBy() Method The keyBy() method is used to keys the collection elements by the given key. If the collection contains multiple items with same key then the last element will appear. Syntax: collect(array).keyBy(key) Parameters: The collect() method takes one argument that is converted into the collection and then 2 min read Like