A collection of pretty useful helper functions.
const lastArrayElement = <TArrayType>(array: Array<TArrayType>): TArrayType => {
// ...
};
First, import it.
import { lastArrayElement } from "helperfunc";
Or, in CommonJS syntax:
const { lastArrayElement } = require("helperfunc");
lastArrayElement()
takes in an array as it’s parameter. It returns the last element of that array.
Here’s how that would work:
const array = [1, 2, 3, 4, 5];
const arrayLast: number = lastArrayElement(array);
console.log(arrayLast); // Will be 5