helperfunc

A collection of pretty useful helper functions.


Project maintained by 0xBooper Hosted on GitHub Pages — Theme by mattgraham

lastArrayElement()

Function Signature:

const lastArrayElement = <TArrayType>(array: Array<TArrayType>): TArrayType => {
  // ...
};

Usage:

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

That’s all you need to know!

Back to homepage