-1

I have an array:

{ExpertiseId: "1Y", ExpertiseName: "Ad-Based Monetization", ExpertiseSubCategory: "Content & Information Services"},
 {ExpertiseId: "2", ExpertiseName: "Balance sheet businesses", ExpertiseSubCategory: null},
 {ExpertiseId: "3", ExpertiseName: "Brand Franchiser or Licenser", ExpertiseSubCategory: "Consumer Brands or IP"},
{ExpertiseId: "4", ExpertiseName: "Branded retail", ExpertiseSubCategory: null},
{ExpertiseId: "5", ExpertiseName: "Wholesale", ExpertiseSubCategory: "Consumer Brands or IP"}

How can I sort it by alphabetical order on ExpertiseSubCategory

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Madinsane
  • 33
  • 3

1 Answers1

0

You could use Array.sort()

A very simple implementation would be:

// assuming the array's name to be "exampleArray"
let sortedArray = exampleArray.sort((a, b) => a.ExpertiseSubCategory.localeCompare(b.ExpertiseSubCategory))
i_arber
  • 178
  • 1
  • 5