I want to sort and array of objects with the property key name. My Array of objects looks like this:
var array = [
{
'version2': {
name: 'abc'
}
},
{
'version1': {
name: 'xyz'
}
}
]
The output expected is something like this:
var array = [
{
'version1': {
name: 'xyz'
}
},
{
'version2': {
name: 'abc'
}
}
]
I tried sorting with this solution but no luck
var abc = array.sort(function(a, b){return Object.keys(a)[0] - Object.keys(b)[0]});
console.log(abc);
The output was same. Please help me out with the solution. Thank you.