Using a function parameter string as a (subvariable?)

Hey guys,

I have this problem with a little search script im working on, in rpg maker mv:

Code:
function searchCategory(term, category, location) {
  for (let i = 1; i < location.length; i++) {
    if (location[i].category === term)
    return location[i];
  }
  return false;
};

example function call:
Code:
searchCategory("THISEVENTSNAME", "name", $dataMap.events);

basically, im replacing "$dataMap.events.name", with "location.category". But I cant seem to get the code to recognize the string inside "category" as a (sub variable?, im not sure what its called). How would I fix this problem?

Thanks in advance!
Code:
location[i][category]
instead.
Code:
location[i].category
is actually asking for a property "category" of location.
@Poryg works, thanks alot!

Original thread: https://forums.rpgmakerweb.com/threads/using-a-function-parameter-string-as-a-subvariable.95861/