Skip to content

Commit 598aca4

Browse files
committed
Merge branches 'master' and 'master' of https://github.com/morrisjdev/Linq4JS
2 parents 0e9860e + 3d228a8 commit 598aca4

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,47 @@ array.FirstOrDefault("i => i.match(/item/gi)");
491491
array.First("i => i == 'notgiven'");
492492
```
493493

494+
### Single
495+
496+
Returns the only item of the array - Throws an exception if not exactly one item is in array
497+
498+
```javascript
499+
var array = ["item1"];
500+
501+
//"item1"
502+
array.Single();
503+
504+
var array = ["item1", "item2"];
505+
506+
//"item1"
507+
array.Single("x => x == 'item1'");
508+
509+
//Exception
510+
array.Single();
511+
```
512+
513+
### SingleOrDefault
514+
515+
Returns the only item of the array - Throws an exception if not only one item is in array
516+
517+
```javascript
518+
var array = ["item1"];
519+
520+
//"item1"
521+
array.Single();
522+
523+
var array = ["item1", "item2"];
524+
525+
//"item1"
526+
array.Single("x => x == 'item1'");
527+
528+
//Exception
529+
array.Single();
530+
531+
//null
532+
array.Single("x => x == 'item3'");
533+
```
534+
494535
### Min
495536

496537
Returns the smallest element in array
@@ -789,4 +830,4 @@ Supported methods (the methodname and aliases are not case-sensitive)
789830

790831
## Author
791832

792-
[Morris Janatzek](http://morrisj.net) ([morrisjdev](https://github.com/morrisjdev))
833+
[Morris Janatzek](http://morrisj.net) ([morrisjdev](https://github.com/morrisjdev))

0 commit comments

Comments
 (0)