JS实现根据数组对象的某一属性排序操作示例

var newArray = [{ name: "aaa", value: 0 }, { name: "ddd", value: 3 }, { name: "bbb", value: 1 }, { name: "eee", value: 4 }, { name: "ccc", value: 2 }]; function compare(property) { return function (a, b) { var value1 = a[property]; var value2 = b[property]; return value1 - value2; } } console.log(newArray.sort(compare("value")))

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/a503b31d013f3ac3a2d018ce110efe70.html