-1

I am trying to get value from $.each and using counter for HTML entity <span>

var counter =1;
        $.each(catCounting, function(){
          alert(catCounting.(countCat+counter));
            $('#countCategory'+counter).html("("+catCounting.(countCat+counter)+")");
            counter++;
          });
        //alert(counter);
      }
HaiderAli
  • 21
  • 7

1 Answers1

1

I'm not entirely sure, but I believe you're trying to get the value at a specific index of catCounting. If this is the case, you need to use the index syntax to find the value which is [] rahter than ().

You don't need to use a . after the variable to do this, so catCounting.(countCat + counter) should become catCounting[countCat + counter]

var counter = 1;

$.each(catCounting, function(){
    alert(catCounting[countCat+counter]));

    $('#countCategory' + counter).html(
        "(" + catCounting[countCat + counter] + ")"
    );

    counter++;
});
James Hay
  • 7,115
  • 6
  • 33
  • 57