0

My array:

item = ['points-a', 'points-b', 'points-c', 'points-d']

My object from a database to save it:

const rating = {
   pointsA = 1,
   pointsB = 2,
   pointsC = 1,
   pointsD = 4,
}

The elements on the page, 4 different input types (all the items in the array are one group of input types):

<input type="radio" class="points-a" name="points-total" value="1" />
<input type="radio" class="points-a" name="points-total" value="2" />
<input type="radio" class="points-a" name="points-total" value="3" />
<input type="radio" class="points-a" name="points-total" value="4" />
<input type="radio" class="points-a" name="points-total" value="5" />

Getting some elements from the page and checking if the value exists to add checked to the correct elements:

['a', 'b', 'c', 'd'].forEach(function(item) {
     document.getElementsByClassName(item).forEach(el) => {
         if (el.value == rating.item) {
            el.checked = true;
         }
     } 
});

How can i make this if (el.value == rating.item) { if statement work? You can see it as object.variable notation?

In PHP i would do $object->$variable.

Looked online couldn't find good refrences so i'm asking here.

Zegert
  • 113
  • 10

0 Answers0