3
In mysql in command SELECT * FROM minha-tabela ORDER BY nome ASC
the list will be returned with all results ordered ascendingly based on the column nome
, i wonder how I can do the same with a js object;
Example:
Object
1: Object
nome: "Batista"
2: Object
nome: "Thiago"
3: Object
nome: "Joana"
4: Object
nome: "Ana"
What would be the function to reorder my object keys alphabetically based on the column nome
to keep it that way:
Object
1: Object
nome: "Ana"
2: Object
nome: "Batista"
3: Object
nome: "Joana"
4: Object
nome: "Thiago"
Does this work for Objects? Because I’m testing here and it says Object.Sort is not a Function, or I have to convert my Object to array?
– Leo Letto
Can you show @Leoletto your code in full? In my example is a
array
of objects– novic
I think there is the problem, because mine is not an array of objects, but an object with other objects inside
– Leo Letto
@Leoletto I want to see this object has how to put, maybe it’s a trivial setting where the ordination is, please post it for me to see!
– novic
This is my real Object the keys must be reordered according to the title marked on the image: http://imgur.com/a/5gGPr
– Leo Letto
Converting the main object to an array and applying its function worked perfectly.
– Leo Letto
I understand that this answer fits your case @Leoletto. In the case, in the end, just turn the array into object. Because the only solution to sort objects is to transform the keys into array and then return to the original converted ones (to sort the keys of an obj for example).
– BrTkCa
@Leoletto are several keys and within several object arrays, if you need to order all?
– novic
Yes, but turning the main object into an array and applying its function worked well : http://imgur.com/a/6Dn8n
– Leo Letto
Poxa @Leoletto truth now straight funfo.
– novic