我试图通过属性对对象数组进行排序title.这是我正在运行的代码片段,但它没有排序任何东西.数组按原样显示.PS我看了以前类似的问题.例如,这里建议并使用我正在使用的相同方法.
javascript:
function sortLibrary() {
// var library is defined, use it in your code
// use console.log(library) to output the sorted library data
console.log("inside sort");
library.sort(function(a,b){return a.title - b.title;});
console.log(library);
}
// tail starts here
var library = [
{
author: 'Bill Gates',
title: 'The Road Ahead',
libraryID: 1254
},
{
author: 'Steve Jobs',
title: 'Walter Isaacson',
libraryID: 4264
},
{
author: 'Suzanne Collins',
title: 'Mockingjay: The Final Book of The Hunger Games',
libraryID: 3245 …Run Code Online (Sandbox Code Playgroud) javascript ×1