en.javascript.info/1-js/4-data-structures/8-array-methods/7-sort-objects/task.md
2016-03-21 10:16:55 +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