js 根据对象数组中的属性进行排序 总结

var compare = function (obj1, obj2) {
                                var val1 = obj1.wareCode;
                                var val2 = obj2.wareCode;
                                if (val1 < val2) {
                                    return -1;
                                } else if (val1 > val2) {
                                    return 1;
                                } else {
                                    return 0;
                                }            
                            } 
                            console.log(result.items[0].wareStocks.sort(compare));

原文地址:https://www.cnblogs.com/huanhuan55/p/11547989.html