lodash orderby with null and real values not ordering correctly

后端 未结 6 716

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...

6条回答
  •  礼貌的吻别
    2021-01-07 23:04

    Just for future reference to others you can do this to sort ascending with falsey values at the end.

    items =>
      orderBy(
        items,
        [
          i => !!i.attributeToCheck,
          i => {
            return i.attributeToCheck ? i.attributeToCheck.toLowerCase() : ''
          }
        ],
        ['desc', 'asc']
      )
    

提交回复
热议问题