Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

lodash
html
javascript
arrays
communitycreator

What is the _.last() method in Lodash?

Shubham Singh Kshatriya

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The _.last() method in Lodash is used to get the last element of an array.

Syntax

_.last(array)
Syntax for the _.last() method

Parameter value

  • array: This is the array that needs to be queried.

Return value

This method returns the last element of the given array.

Example

Console
Implementation of the _.last() method

Explanation

In the HTML tab:

  • Line 5: We import the lodash script.

In the JavaScript tab:

  • Line 2: We create an array called numbers and populate it with a few values.
  • Line 5: We use the _.last() method to get the last element of the numbers array.
  • Line 8: We print the last element of the numbers array, 2, to the console.

RELATED TAGS

lodash
html
javascript
arrays
communitycreator

CONTRIBUTOR

Shubham Singh Kshatriya

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring