How to sort object array based on key in typescript

This question already has an answer here:

  • Sort array of objects by string property value in JavaScript 33 answers

  • It's the same as plain old javascript. You can still use an arrow function to make it more concise.

    x.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)
    

    Or using localeCompare .

    x.sort((a, b) => a.name.localeCompare(b.name))
    
    链接地址: http://www.djcxy.com/p/19326.html

    上一篇: 排序一个json列表?

    下一篇: 如何在打字稿中基于键排序对象数组