-
Notifications
You must be signed in to change notification settings - Fork 3
FirstOrDefault
Yasser Moradi edited this page Aug 26, 2015
·
3 revisions
Description:
This method is similar to first method , However if no item exists , it does not throw an exception. It returns null.
let items = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten'];
let first = items.asEnumerable().firstOrDefault();
console.log(first);
first = empty.asEnumerable().firstOrDefault();
console.log(first);
Description:
You can pass an argument as a predicate. The returned value is the first item of the list that matches that predicate criteria.
Sample:
first = items.asEnumerable().firstOrDefault(item => item.length == 5);
console.log('first item is equals 5 length => ' + first);