Answer the question
In order to leave comments, you need to log in
Where does the function get its variables from?
var users = [{
name: "Вася",
surname: 'Иванов',
age: 20
}, {
name: "Петя",
surname: 'Чапаев',
age: 25
}, {
name: "Маша",
surname: 'Медведева',
age: 18
}];
function byField(field){
return function (a,b){
return a[field] > b[field] ? 1 : -1;
}
}
users.sort(byField('name'));
users.forEach(function(user) {
alert( user.name );
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question