This question has already been answered:

There is an array of the form

var arr = [ { fiels: { name: "a", alt: "a2" }, count: 4 }, { fiels: { name: "b", alt: "3" }, count: 3 }, ]; 

You need to sort the array in two ways:

  1. For the value of "fields.name".
  2. By count.

How can this be realized?

Reported as a duplicate at Grundy. javascript 21 Mar '18 at 7:16 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Wikipedia has an implementation of sorting on js. Instead of an array element, refer to the corresponding object variable. When sorting by name, compare the first character of the name. If one of the words lacks a symbol, if the previous letters match, consider this element to be smaller. The characters are consecutively numbered, so that 'a' <'b'. Good luck - Garden Chamber

2 answers 2

That's what happened

 var json = vehicle.sort(function(one, two) { if (one.name < two.name) return -1; if (one.name > two.name) return 1; return 0; }); 

    By value "fields.name":

     arr.sort(function (a, b){ return a.fiels.name > b.fiels.name }); 

    By count:

     arr.sort(function (a, b){return a.count - b.count});