Javascript 如何在ReactJS中对Google Books API标题和作者进行排序

Javascript 如何在ReactJS中对Google Books API标题和作者进行排序,javascript,reactjs,sorting,google-books,Javascript,Reactjs,Sorting,Google Books,在为书店实现浏览和排序功能时,我还没有找到对字符串/数组进行排序的方法。在API中,标题是字符串,作者存储在数组中。下面是一段关于评级、发布日期和价格的排序过程 const filteredBooks=this.state.books.sort((a,b)=>{ const price1=a.saleInfo.hasOwnProperty('listPrice')==false?$0.00:a.saleInfo.listPrice.amount; const price2=b.saleInfo.

在为书店实现浏览和排序功能时,我还没有找到对字符串/数组进行排序的方法。在API中,标题是字符串,作者存储在数组中。下面是一段关于评级、发布日期和价格的排序过程

const filteredBooks=this.state.books.sort((a,b)=>{
const price1=a.saleInfo.hasOwnProperty('listPrice')==false?$0.00:a.saleInfo.listPrice.amount;
const price2=b.saleInfo.hasOwnProperty('listPrice')==false?$0.00:b.saleInfo.listPrice.amount;
const title1=a.volumeInfo.hasOwnProperty('title')==false?“NA”:a.volumeInfo.title;
const title2=a.volumeInfo.hasOwnProperty('title')==false?“NA”:a.volumeInfo.title;
if(this.state.sort==='Newest'){
console.log(“最新登录”)
返回parseInt(b.volumeInfo.publishedDate.substring(0,4))-parseInt(a.volumeInfo.publishedDate.substring(0,4));
}
else if(this.state.sort==‘最早’){
返回parseInt(a.volumeInfo.publishedDate.substring(0,4))-parseInt(b.volumeInfo.publishedDate.substring(0,4));
}
else if(this.state.sort=='High'){
返回parseInt(b.volumeInfo.averageRating)-parseInt(a.volumeInfo.averageRating);
}
else if(this.state.sort=='Low'){
返回parseInt(a.volumeInfo.averageRating)-parseInt(b.volumeInfo.averageRating);
}
else if(this.state.sort==‘昂贵’){
返回parseInt(price2)-parseInt(price1);
}
else if(this.state.sort===‘便宜’){
返回parseInt(price1)-parseInt(price2);
}
else if(this.state.sort=='Title-A'){
返回标题2-标题1;
}
返回;
})
我对react和javascript非常陌生,因此我非常感谢您的帮助。谢谢