The object
var obj = {
uniquestring1:
{
obj1: 'content',
obj2: 'content'
},
uniquestring2:
{
obj1: 'content'
}
}
So i need to sort the object by number of the elements contained by the first parent element. The use of .sort function is not a sollution for me because i need to maintain the index assosiaction which array’s dont keep.
The result should be:
var obj = {
uniquestring2:
{
obj1: 'content'
},
uniquestring1:
{
obj1: 'content',
obj2: 'content'
}
}
Javscript objects don’t have a sort order so they can’t be sorted. To sort, you must have an array somewhere and I see no array in your code.
Object keys have no defined order.
You could do a one-time creation of a parallel array that contained key references in sorted order like this:
Then, to traverse the keys in sorted order, you would do it like this: