my-idlers/node_modules/collect.js/docs/api/whenEmpty.md
cp6 fd22b0bf58 V2 (Laravel re-make)
V2 (Laravel re-make)
2022-03-06 02:02:12 +11:00

31 lines
561 B
Markdown

# `whenEmpty()`
The `whenEmpty` method will execute the given callback when the collection is empty:
```js
const collection = collect([]);
collection.whenEmpty(c => c.push('Mohamed Salah'));
collection.all();
// ['Mohamed Salah']
```
```js
const collection = collect(['Sadio Mané']);
collection.whenEmpty(
c => c.push('Mohamed Salah'),
c => c.push('Xherdan Shaqiri'),
);
collection.all();
// [
// 'Sadio Mané',
// 'Xherdan Shaqiri',
// ];
```
[View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/whenEmpty.js)