I want increment a global variable conditionally for a list of items

Viewed 40

I am rendering an array of strings. I have a global variable "structureCount". I have some strings stored in redux store. I want to increment "structureCount" whenever strings from redux store matches the strings from the array I am rendering. And if the strings don't match "structureCount" will be 0 for those.

let addedStr = 0;
    if (data.structures.structures) {
      data.structures.structures.forEach((str) => {
        if (str) {
          this.costCentre.forEach((centre) => {
            if (centre === str.cost_centre) {
              addedStr += 1;
            } else {
              addedStr = 0;
            }
          });
        } else {
          console.log("Not Exists");
        }
      });
    }
0 Answers
Related