I have a hand-typed database with an object that has categories and a list of words for each category, as below:
var words =
{
sports: [
'baseball', 'football', 'volleyball', 'basketball', 'soccer'],
animals: [
'dog', 'cat', 'elephant', 'crocodile', 'bird'],
entertainment: [
'netflix', 'movies', 'music', 'concert', 'band', 'computer']
}
My HTML has a bootstrap dropdown that will display all categories based on that list. I have the code working to give me the value of the category clicked as a string: as below:
$(document).on('click', '.dropdown-menu li a', function () {
var selectedCategory;
selectedCategory = $(this).text();
//setting value of category to global variable
categorySelected = selectedCategory;
});
I need to be able to find the key in my database from that value. The problem is that I can't access words."animals" I need to take the quotation marks off my string to get the list of words like this: words.animals
How do I do this? I've tried replace() but it doesn't work.