Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  193] [ 5]  / answers: 1 / hits: 23708  / 8 Years ago, wed, december 14, 2016, 12:00:00

I have an Angular 2 typescript application that is using lodash for various things.



I have an array of objects that I am ordering using a property in the object...



_.orderBy(this.myArray, ['propertyName'], ['desc']);


This works well however my problem is that sometimes 'propertyName' can have a null value.
These are ordered as the first item in a descending list, the highest real values then follow.



I want to make these null values appear last in the descending ordering.



I understand why the nulls come first.



Does anyone know how to approach this?


More From » typescript

 Answers
15

The code I needed looks like this...



_.orderBy(this.myArray, [( o ) => { return o.myProperty || ''}], ['desc']); 

[#59707] Monday, December 12, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kerryoliviaa

Total Points: 221
Total Questions: 102
Total Answers: 117

Location: Sint Maarten
Member since Tue, Mar 29, 2022
2 Years ago
;