Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Add a variable to a response path

I'm trying to add a variable into a path like this:

response.response.body.result.company.data.t${variable}.month_col_val[i]

I know it's wrong, yet I'm not being able to find if it's actually posible to do it and how to do it. My json file contains objects named t0, t1, t2... and so on inside data, so i'm trying to get an specific one by adding the variable value along the T

Variable is define outside the fuction and pass as a parameter.

for (let o = 0; o < 12; o++) {
                    cy.get($el).find('.month-data-cols').eq(o).invoke('text').then($text => {
                        let monthGross = $text
                        let monthGrossReq = response.response.body.result.company.data.t${variable}.month_col_val[o]
                        monthGross = monthGross.toString().replace(/,/g, '').trim();
                        expect(monthGross).to.include(monthGrossReq);
                    })
                };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try using square-bracket notation instead of dot-notation at that property

const data = response.response.body.result.company.data
const monthGrossReq = data[`t${variable}`].month_col_val[o]
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!