Files
ihrm/node_modules/collect.js/docs/api/first.md
Nikhil Ravi Cybrosys e1794e7422 [UPDT]translations in the views (#4)
[UPDT]Translations in the views
[FIX]major bug fixes
2023-05-18 15:05:28 +05:30

19 lines
475 B
Markdown
Executable File

# `first()`
The first method returns the first element in the collection that passes a given truth test:
```js
collect([1, 2, 3, 4]).first(item => item > 1);
// 2
```
You may also call the first method with no arguments to get the first element in the collection. If the collection is empty, null is returned:
```js
collect([1, 2, 3, 4]).first();
// 1
```
[View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/first.js)