Assuming that Misa's bookshelf is an array of objects in the format {title: "Book Title", author: "Author Name", ...}
), you can count how many books are on her bookshelf using the Array.prototype.reduce()
method:
index.tsx306 chars11 lines
In the above code, reduce()
iterates over each book in misasBookshelf
and adds 1
to the count
variable for each book, starting from an initial value of 0
.
The resulting bookCount
variable contains the total number of books on Misa's bookshelf, which is then output to the console using a template literal.
gistlibby LogSnag