Answer the question
In order to leave comments, you need to log in
Sorting nested js object?
there is an object:
how to sort it according to the value of the nested object attribute_1:
Now - so
var data = [];
data[0]={ 'attributes' : {'attribute_1' : "60",'attribute_2' : "90"}, 'var' : 'false'};
data[1]={ 'attributes' : {'attribute_1' : "90",'attribute_2' : "90"}, 'var' : 'false'};
data[2]={ 'attributes' : {'attribute_1' : "50",'attribute_2' : "90"}, 'var' : 'false'};
var data = [];
data[0]={ 'attributes' : {'attribute_1' : "50",'attribute_2' : "90"}, 'var' : 'false'};
data[1]={ 'attributes' : {'attribute_1' : "60",'attribute_2' : "90"}, 'var' : 'false'};
data[2]={ 'attributes' : {'attribute_1' : "90",'attribute_2' : "90"}, 'var' : 'false'};
Answer the question
In order to leave comments, you need to log in
var items = [
{ name: 'Edward', value: 21 },
{ name: 'Sharpe', value: 37 },
{ name: 'And', value: 45 },
{ name: 'The', value: -12 },
{ name: 'Magnetic' },
{ name: 'Zeros', value: 37 }
];
items.sort(function (a, b) {
if (a.name > b.name) {
return 1;
}
if (a.name < b.name) {
return -1;
}
// a должно быть равным b
return 0;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question