Sort Array of Objects by specific key value
This question already has an answer here:
You can use localeCompare method which will returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order.
var sorted = array.sort((a, b) => {
return a.subreddit.localeCompare(b.subreddit)
});
DEMO
链接地址: http://www.djcxy.com/p/19338.html上一篇: 按数组索引排序
下一篇: 按特定键值排序对象数组