Underscore.js is a utility library for JavaScript that provides a lot of useful methods for working with collections, arrays and objects. One of the methods provided by Underscore.js is the select
function, which is used to filter a collection based on a given predicate function.
In order to use the select
function from Underscore.js in TypeScript, you first need to install the library:
index.ts23 chars2 lines
Then, you can import the select
function from the underscore
module:
index.ts37 chars2 lines
The select
function takes two parameters: the collection to filter, and the predicate function to use for filtering.
Here's an example of how to use the select
function in TypeScript:
index.ts340 chars17 lines
In this example, we're using the select
function to filter the people
array based on the age property of each person. The predicate function returns true for people with an age less than 30, so the resulting array contains only Alice.
gistlibby LogSnag