rst*_*rim 2 javascript underscore.js
我有一个对象数组.我想使用underscore.js按各自的值对每个对象进行排序.
var myArray = [
{a:1, b:2, c:2},
{a:1, b:3, c:2},
{a:3, b:2, c:1},
{a:1, b:1, c:4},
{a:1, b:2, c:4},
];
Run Code Online (Sandbox Code Playgroud)
我试过这种方法没有运气......
var myArray = [
{a:1, b:2, c:2},
{a:1, c:2, b:3},
{c:1, b:2, a:3},
{a:1, b:1, c:4},
{a:1, b:2, c:4},
];
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用这种方法.
_.each(myArray, function(obj) {
_(obj).sortBy(function(val, key) {
return val;
});
Run Code Online (Sandbox Code Playgroud)
});