getQuery()
{
    let countOfElements = 0;
    let query=""
     cy.get("elementid").then($elements => {
      countOfElements = $elements.length;
      console.log(countOfElements)
      for (let i = 0; i < countOfElements; i++) {
        cy.get("elementid").eq(i).then( $value => {
          const textValue = $value.text()
          query =query + " " + textValue
        })
      }
      cy.log(query)
    });
    return query
}
I am trying to get the text inside one element which scattered in multiple spans.my logic is follows
1: from the parent path get the total number of spans
2: Get the text from each span and append each other by looping through all the spans
Problem 1: return query is always coming as empty, how I can store the value and return the concatenated query?
 
    