To use the sample function from the lodash library in TypeScript, you first need to import it from the library:
index.ts33 chars2 lines
Then, you can use the sample function to get a random element from an array. Here's an example:
index.ts180 chars4 lines
In this example, we create an array of fruits and then use the sample function to get a random fruit from the array. The randomItem variable will contain the randomly selected fruit, which we then log to the console.
Note that the sample function can be used with any array, regardless of the data type of the array elements.
gistlibby LogSnag