0

My object is in this form:

const objectName = {
 "Name": "XYz"
 "Roll": "34"
 "badgeNo": undefined
 "fatherName": "abc"
 "motherName": null
 }

want to sort the object by value of this key-value object

mgm793
  • 1,968
  • 15
  • 23
GulamMd
  • 9
  • 3
  • can you show the required output, and some useful input variable – Jaromanda X Sep 06 '22 at 06:31
  • Object members are inherently unsorted, it's not possible without adding additional structure to provide the sorting. You ok with that? (Or did you actually mean you want to know how to sort a collection of objects like this?) – Tibrogargan Sep 06 '22 at 06:39
  • @Tibrogargan - not quite true - non-numeric keys are in "creation" order - so you can sort the "keys" – Jaromanda X Sep 06 '22 at 06:41
  • @JaromandaX yes, but frankly that doesn't really lend itself to sorting in a terribly useful manner. Especially if the OP is trying to sort the properties in order of their values. – Tibrogargan Sep 06 '22 at 06:45
  • @Tibrogargan - I whole heartedly agree - there's never a good reason to have keys in an object in a particular order - if you need that, then you're doing javascript wrong! I think the second part of your comment is probably closer to what the OP wants anyway :p – Jaromanda X Sep 06 '22 at 06:46

0 Answers0