function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aruna Anala 6Aruna Anala 6 

How to perform sorting for object of array objects

Eg:
const obj ={
  x:[
    {
      name:"Aruna",
      Position:"3"
    },
    {
      name:"Sri",
      Position:"1"
      }
]
};

How to perform sorting based on position in JavaScript
SwethaSwetha (Salesforce Developers) 
HI Aruna,
Your question is more aligned to Javascript than Salesforce and is best suited to be posted on https://stackoverflow.com/

Check https://www.educative.io/edpresso/how-to-sort-an-array-of-objects-in-javascript that should help you get started

Please consider marking the answer as best if this helps.Thank you
Malika Pathak 9Malika Pathak 9
Hi Aruna
This might help you
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_list_sorting_sobject.htm

I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Dushyant SonwarDushyant Sonwar
Aruna,

If you want to sort below object
const obj ={
  x:[
    {
      name:"Aruna",
      Position:"3"
    },
    {
      name:"Sri",
      Position:"1"
      }
]
};


On the basis of name 
obj.x.sort((a,b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0));
console.log(obj);

On the basis of position
obj.x.sort((a,b) => (a.Position > b.Position) ? 1 : ((b.Position > a.Position) ? -1 : 0));
console.log(obj);

Note : Javascript is case sensitive language, so be careful with lowecases and uppercases.

Hope this helps!