原数据:
let arr = [
[
{price: 46, userUid: 0, item_name: '测试1', min: 41, max: 50},
{price: 87, userUid: 0, item_name: '测试1', min: 81, max: 90},
{price: 24, userUid: 89779, item_name: '测试1', min: 21, max: 30}
],
[
{price: 15, userUid: 0, item_name: '测试2', min: 11, max: 20},
{price: 58, userUid: 0, item_name: '测试2', min: 51, max: 60},
{price: 92, userUid: 0, item_name: '测试2', min: 91, max: 100},
{price: 103, userUid: 0, item_name: '测试2', min: 101, max: 110},
],
[
{price: 9, userUid: 43062, item_name: '测试3', min: 1, max: 10},
{price: 65, userUid: 0, item_name: '测试3', min: 61, max: 70},
],
[
{price: 36, userUid: 0, item_name: '测试4', min: 31, max: 40},
{price: 72, userUid: 0, item_name: '测试4', min: 71, max: 80}
]
]
根据arr数组里面的price字段排序
期望得到:
let items = [
[
{price: 9, userUid: 43062, item_name: '测试3', min: 1, max: 10},
{price: 46, userUid: 0, item_name: '测试1', min: 41, max: 50},
{price: 87, userUid: 0, item_name: '测试1', min: 81, max: 90},
],
[
{price: 15, userUid: 0, item_name: '测试2', min: 11, max: 20},
{price: 58, userUid: 0, item_name: '测试2', min: 51, max: 60},
{price: 92, userUid: 0, item_name: '测试2', min: 91, max: 100},
{price: 103, userUid: 0, item_name: '测试2', min: 101, max: 110},
],
[
{price: 24, userUid: 43062, item_name: '测试1', min: 1, max: 10},
{price: 65, userUid: 0, item_name: '测试3', min: 61, max: 70},
],
[
{price: 36, userUid: 0, item_name: '测试4', min: 31, max: 40},
{price: 72, userUid: 0, item_name: '测试4', min: 71, max: 80}
]
]
麻烦各位大佬帮我看看
arr.forEach(subArray => {
subArray.sort((a, b) => a.price - b.price);
});
let items = arr;
console.log(items);