云函数sort 如何根据数组里面对象里面的数组长度进行排序?

微信问答 文章 2021-12-03 14:40 463 0 全屏看文

AI助手支持GPT4.0

云函数sort 如何根据数组里面对象里面的数组长度进行排序?How does the cloud function sort sort according to the length of the array in the objects in the array?

云函数sort 如何根据数组里面对象里面的数组长度进行排序?

根据数组里面的对象中的数组长度进行排序,。

s数据库内容 =  [{a :1,b:[1]},{a :1,b:[1,2,3]}{a :1,b:[1,2]}]排序后的结果,我希望是 = [{a :1,b:[1,2,3]},{a :1,b:[1,2]}{a :1,b:[1]}]

Sort according to the array length of the objects in the array,. S database content = [{A: 1, B: [1]}, {A: 1, B: [1,2,3]} {A: 1, B: [1,2]}] sorted results, I hope = [{A: 1, B: [1,2,3]}, {A: 1, B: [1,2]} {A: 1, B: [1]}]

鍥炵瓟锛�

brave:
arr.sort((m, n) => m.b.length - n.b.length)
中式小面包:

arr.sort((item1,item2) => item1.b.length - item2.b.length)

老张:
.xxx.aggregate().project({  len:$.size("$b")}).sort()
微喵网络:

先遍历一遍,计算长度,增加一项

再根据新增项排序

-EOF-

AI助手支持GPT4.0