en.javascript.info/1-js/6-data-structures/7-array-methods/7-sort-objects/task.md
Ilya Kantor 3f5f2cac8b work
2016-07-22 20:47:41 +03:00

397 B

importance: 5


Sort objects

Write the function sortByName(users) that gets an array of objects with property name and sorts it.

For instance:

let john = { name: "John", age: 25 }
let pete = { name: "Pete", age: 30 }
let mary = { name: "Mary", age: 28 }

let arr = [ john, pete, mary ];

lsortByName(arr);

// now: [john, mary, pete]
alert(arr[1].name) // Mary