图书馆信息列表中有4本不同名称的编程书,筛选书籍并展示信息js
时间: 2024-09-14 17:08:43 浏览: 41
在JavaScript中,我们可以创建一个简单的图书馆信息对象数组来模拟这个场景。假设我们有以下四本书的信息:
```javascript
let libraryBooks = [
{
title: "JavaScript高级程序设计",
author: "Nicholas C. Zakas",
publicationYear: 2019,
genre: "Web Development"
},
{
title: "Python Crash Course",
author: "Eric Matthes",
publicationYear: 2016,
genre: "Programming Basics"
},
{
title: "C++ Primer",
author: "Lippman, Lajoie, and Moo",
publicationYear: 2017,
genre: "Object-Oriented Programming"
},
{
title: "Head First Design Patterns",
author: "Eric Freeman and Elisabeth Robson",
publicationYear: 2004,
genre: "Design Patterns"
}
];
// 筛选书籍函数
function filterBooks(genre) {
return libraryBooks.filter(book => book.genre === genre);
}
// 按照指定的编程语言筛选并显示信息
let javascriptBooks = filterBooks("Web Development");
console.log(javascriptBooks);
阅读全文