object sort
-
[JS] 객체 배열 정렬JavaScript 2020. 11. 30. 10:11
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 ? ..