how to use the last function from the underscore library in javascript

The last function from the Underscore library in JavaScript returns the last element of an array. Here's an example of how to use it:

index.tsx
const _ = require('underscore');

const arr = [1, 2, 3, 4, 5];

const lastElement = _.last(arr);

console.log(lastElement); // 5
129 chars
8 lines

In the example above, we first require the Underscore library. Then, we define an array arr and call the last function on it using the Underscore object _. The last function returns the last element of the array, which in this case is 5.

We then log the lastElement to the console which outputs 5.

gistlibby LogSnag