Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

比较对象里面字段的数字大小,取得最高的4个

就是说我有一个数组,数组里面有N个对象,对象里面有个字段count是0,每次我点击一个对象,里面的count就+1, 我会取count数字最高的4个存入新数组里面,然后进行从大到小排序,这个怎么弄呢
[
{count:0,name:'1'},
{count:0,name:'2'},
{count:0,name:'3'},
{count:0,name:'4'},
...
]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

数组根据count属性值大小排序,取前四个不就好了,这js最基础的东西啊,好好学吧,少年


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...