File tree Expand file tree Collapse file tree 1 file changed +42
-1
lines changed
Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -491,6 +491,47 @@ array.FirstOrDefault("i => i.match(/item/gi)");
491491array .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
496537Returns 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 ) )
You can’t perform that action at this time.
0 commit comments