嗨,我有3个复选框MostCommented,MostRead,MostLiked,默认情况下,所有这些都将被单击。通过检查,我应该能够过滤我的数组。我的数组在下面。
array = [{"LikeCount:2,commentCount:4,ReadCount:6"},
{"LikeCount:1,commentCount:1,ReadCount:3"},
{"LikeCount:4,commentCount:2,ReadCount:3"},
{"LikeCount:4,commentCount:1,ReadCount:1"},
{"LikeCount:4,commentCount:2,ReadCount:5"},
{"LikeCount:4,commentCount:3,ReadCount:1"},
{"LikeCount:5,commentCount:3,ReadCount:5"}]
我需要这样的输出。
array = [{"LikeCount:5,commentCount:3,ReadCount:5"},
{"LikeCount:4,commentCount:1,ReadCount:3"},
{"LikeCount:4,commentCount:2,ReadCount:3"},
{"LikeCount:4,commentCount:2,ReadCount:3"},
{"LikeCount:4,commentCount:3,ReadCount:5"},
{"LikeCount:2,commentCount:4,ReadCount:6"},
{"LikeCount:1,commentCount:1,ReadCount:3"}]
任何输入都会有帮助。
您的预期输出显示您需要根据LikeCount
进行排序,所以>
尝试一下:
let array = [{ LikeCount: 2, commentCount: 4, ReadCount: 6 },
{ LikeCount: 1, commentCount: 1, ReadCount: 3 },
{ LikeCount: 4, commentCount: 2, ReadCount: 3 },
{ LikeCount: 4, commentCount: 1, ReadCount: 1 },
{ LikeCount: 4, commentCount: 2, ReadCount: 5 },
{ LikeCount: 4, commentCount: 3, ReadCount: 1 },
{ LikeCount: 5, commentCount: 3, ReadCount: 5 }]
array.sort(function (a, b) {
return b.LikeCount - a.LikeCount
})
console.log(array);