Arun, ask not what jQuery can do for you, ask what you can do for... Well, something like that.
Did you look at what makeArray() gave you back? Do a console.log() if you didn't try it. You'll see that it's not what you were expecting - makeArray() isn't meant for this purpose. Don't rely on a library function to do this conversion for you (unless you know it's the right one) - it's only 2-3 lines of code anyway, so just write it yourself and get exactly what you need. But first you need to decide exactly what the output should be. It can't be what you posted in your first message - that's not an array. Is the array format I listed OK? Or do you need to also preserve those numeric keys, maybe by adding a third property to each element: ... { "Key" : 2, "Name" : "B", "Position" : "Sr" }, ... Once you have the exact format in mind, it's a simple bit of code to create the array. Don't think about sorting until you have verified the array contents. Then, sort with a callback function and you're done. -Mike > From: Arun Kumar > > what about using jQuery.makeArray() method? > > I tried this and converted that object into an array and then I used > sort() method. But no use. > On Jun 27, 12:33 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote: > > No, you can't do that. Your jsonObj is an *object*, not an > > array, so it has no sort order. > > > > If you want to be able to sort your object, it needs to be > > an array, e.g. > > > > var jsonObj = [ > > { > > "Name" : "B", > > "Position" : "Sr" > > }, > > { > > "Name" : "S", > > "Position" : "Sr" > > }, > > { > > "Name" : "A", > > "Position" : "Jr" > > } > > ]; > > > > That is something you can sort. You can use JavaScript's > > sort() method of the Array object with a callback function > > that compares two elements as you wish. > > > > If you have a large number of elements in the array, a sort > > callback can slow down sorting. Let me know if this is the > > case - I have a very fast array sort method for just this > > situation. To late at night for me to post it right now, but > > remind me tomorrow... > > > From: Arun Kumar > > > > > I have a JSON object (dynamically created) which is given below: > > > > > var jsonObj = { > > > 1 : { > > > "Name" : "B", > > > "Position" : "Sr" > > > }, > > > 2 : { > > > "Name" : "S", > > > "Position" : "Sr" > > > }, > > > 3 : { > > > "Name" : "A", > > > "Position" : "Jr" > > > } > > > }; > > > > > In the above JSON object, keys can be strings also. > > > > > Is there anyway that I can sort this JSON object based > > > on these keys? > > > > > The output should be as below: > > > > > var jsonObj = { > > > 2 : { > > > "Name" : "Sai", > > > "Position" : "Sr" > > > }, > > > 1 : { > > > "Name" : "Bhushan", > > > "Position" : "Sr" > > > }, > > > 3 : { > > > "Name" : "Arun", > > > "Position" : "Jr" > > > } > > > };