I need help sorting an array of objects received from the server in ascending order based on the uid key, while keeping the original array intact. The array I'm working with has 2 elements in the data array. I want to analyze the uid values in each element and arrange them accordingly within the data array.
Although I attempted to use lodash for this task, it doesn't seem to be functioning correctly. I believe I am close to the solution and would appreciate some guidance:
// sort by:
console.log(res.results[0].data[0].row[1].uid)
_.forEach(res.results, function(obj) {
_.forEach(data, function(anotherObj) {
_.forEach(row, function(row) {
data.row = _.sortBy(data.row, function(row) {
return row[1].uid;
});
});
});
});
Here is the array of objects retrieved from the server:
var res = {
results: [{
columns: ['large', 'medium', 'small'],
data: [{
row: [{
sid: 13,
tid: 427
},
{
uid: 69,
vid: 450,
wid: 65
},
null],
multirow: {
nodule: [{
xid: '427',
properties: {
yid: 13,
zid: 427
}
},
{
aid: '450',
properties: {
uid: 69,
bid: 450,
cid: 65
}
}]
}
},
{
row: [{
sid: 13,
tid: 427
},
{
vid: 432,
uid: 65,
wid: 61
},
null],
multirow: {
nodule: [{
xid: '427',
properties: {
yid: 13,
zid: 427
}
},
{
aid: '432',
properties: {
bid: 432,
uid: 65,
cid: 61
}
}]
}
}]
}],
errors: []
};