Checking if element has class that matches object key

for(let [key, value] of Object.entries(dropdownData)) {
  if($.inArray(key, _.attr("class").split(" "))) {
    console.log("key found class:"+key);;

I have 40 or so elements. These elements can have a variety of classes on them. I am trying to loop over each of these elements to see if they have a class that matches one of these keys

const dropdownData = {
  "elementary": "Elementary Schools",
  "middle": "Middle Schools",
  "high": "High Schools",
  "center": "Centers"

Even though I have multiple elements with other classes, I ONLY get “elementary” returned in my console log. Where’s my logic going wrong here? I read the for loop code as:
For loop will make it so I can loop over each key value Then I use the If statement to check whether my element _ has a class that matches my key

The first 20 or so have “elementary” but then the next several should be middle, then high, then center.

I’m sleep deprived I imagine; got it…
if(self.attr("class").split(" ").includes(key)) {
Where self = the element.


EDIT: Apparently markdown breaks if you put parenthesis in your link.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.