const commentCountList = [
{ postId: 1, commentCount: '5' },
{ postId: 2, commentCount: '1' },
{ postId: 3, commentCount: '1' },
{ postId: 4, commentCount: '3' },
{ postId: 5, commentCount: '1' },
{ postId: 6, commentCount: '4' }
]
const result = commentCountList
.sort((target1, target2) => {
return target1.commentCount > target2.commentCount
? -1
: target1.commentCount < target2.commentCount
? 1
: 0;
});
// result
[
{ postId: 1, commentCount: '5' },
{ postId: 6, commentCount: '4' },
{ postId: 4, commentCount: '3' },
{ postId: 2, commentCount: '1' },
{ postId: 3, commentCount: '1' }
]