Search code examples
javascriptconcatenationstring-concatenation

JavaScript - Concatenate a value within variable


I know that this is somewhat, very basic question, but.. I have to create a cypress element, for which I have to concatenate a value between variables.

Like I have this value

const value = "100 - 299"

and I have to print a value within a string, i.e.

cy.get('[data-value="100 - 299"]')

I am trying everything but unable to do so. Can someone help me on this?


Solution

  • I would consider template literals - also called backticks

    cy.get(`[data-value="${value}"]`)