how to use the head function from the underscore library in typescript

To use the head function from the Underscore library in TypeScript, you can follow these steps:

  1. Install the Underscore library by running npm install underscore in your project folder.
  2. Import the head function from the library in your TypeScript file:
index.ts
import { head } from 'underscore';
35 chars
2 lines
  1. Use the head function to get the first element of an array:
index.ts
const arr: string[] = ['a', 'b', 'c'];
const firstElement: string = head(arr);
// firstElement will equal 'a'
110 chars
4 lines

That's it! Now you can use the head function in your TypeScript projects.

gistlibby LogSnag