'Cannot find element with static id on page

i am new to cypress and here is my problem. I have a table that has a dynamic id for each entry. i want to have a function that gets the data from the table and checks if it contains a value i calculate. The problem i am facing is that when the cy.get tries to find the element and see if it contains a value it says it cant find element (if i check for attribute x it finds it) so i am thinking it might be because i declare the ID constant in the each function. Thank you for your time!

cy.get(tableElement).each(($element, index) = {
      cy.log(`Table element is ${tableElement[index]}`)      
      someFormula = value1 + value2   
      cy.log(`Cypress element ${tableElement[index]} team is ${someFormula}`)
      const realValueFromTable = `#id_${tableElement[index]}`
      cy.log(realValueFromTable) //here i can see the full id #id_example1          
      cy.get(realValueFromTable).contains(someFormula) 
//here it stays at get #id_example1 it should get the value from that id and compare it with the formula value


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source