0

I have the following json output for products:

{
  "userProducts": [
    {
      "velas": "yes",
      "bobina": "yes",
      "aquecedoras": "no",
      "sensores": "yes",
      "terminais": "no",
      "cabos": "yes",
      "especiais": "no"
    },
    {
      "velas": "no",
      "bobina": "no",
      "aquecedoras": "no",
      "sensores": "no",
      "terminais": "no",
      "cabos": "yes",
      "especiais": "no"
    }
  ]
}

I'm calling this json from my server, i need to sort in 2 different ways: First: Order by user that sells more product types Second: Order Alphabetically

So the output need to be something like:

  • Users that sells 5 products
  • Users that sells 4 products
  • Users that sells 3 products

How can i do that?

William Xavier
  • 478
  • 3
  • 20
  • 3
    [`Array.prototype.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) – 4castle Jul 18 '16 at 18:37
  • 1
    Writing code would be a good start. We're not here to do your job for you. You write code, explain how it's NOT working, and we'll (maybe) try help fix it. – Marc B Jul 18 '16 at 18:37
  • 1
    Possible duplicate of [Sort array of objects by string property value in JavaScript](http://stackoverflow.com/questions/1129216/sort-array-of-objects-by-string-property-value-in-javascript) – Matthew Herbst Jul 18 '16 at 18:41
  • If you want sort your array by product type sold, you should add a property numberType to each element – kevin ternet Jul 18 '16 at 19:21

0 Answers0