Hi all I have an array of objects (20 of them) that I\'ve placed in this format to make columns in an Angular Project (note there are objects in objects). I want to sort the
For your data structure you can use sort()
like this.
var arrayOfObjects = [
{"least#OfKeysObject": {
key1: 'value',
}
},
{"secondMost#OfKeysObj": {
key1: 'value',
key2: 'value'
}
},
{"most#OfKeysObj": {
key1: 'value',
key2: 'value',
key3: 'value'
}
}
];
var result = arrayOfObjects.sort(function(a, b) {
return Object.keys(b[Object.keys(b)[0]]).length - Object.keys(a[Object.keys(a)[0]]).length;
});
console.log(result)