I'm trying to create a javascript object that would easily let me check how many chapters there are in a certain book and how many verses there are in a certain chapter.
My plan is to have a structure like this for the object:
const amounts = {
book: {
bookNumber: 1,
bookChapters: 50,
chapter:
{
chapterNumber: 1,
versesInChapter: 31
},
chapter:
{
chapterNumber: 2,
versesInChapter: 25
}
},
book: {
bookNumber: 2,
bookChapters: 40,
chapter:
{
chapterNumber: 1,
versesInChapter: 26
},
chapter:
{
chapterNumber: 2,
versesInChapter: 22
}
}
}
How could I access the nested values of such a structure based on variable values? For example I might have a var bookNum = 2 and var chapterNum = 2 and my goal would be to get the number of verses in chapter 2 inside book 2. How would I write such a query?
EDIT: Based on the comments my object structure is also bad, so I'm asking to also point out the correct structure that would allow me to access the amount of verses efficiently.
chaptermeant to be an array? And, for that matter, shouldn't eachbookhave a unique name? Currently the last property will override the first, leaving you with a single book containing a single chapter.bookwhich will overwrite the first one. And same will happen withchapter