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

179
Views
How can I use one variable with another in Vue JavaScript?
const n = this.prac
const x = this.oa
console.log(x)
console.log(n[0].x)

So n stores data from a JSON file with columns like Organizations, Title etc. oa will have a value given as input by the user. Let's suppose user inputs Organizations I want to print n[0].x i.e n[0].Organizations but when I do console.log(n[0].x) it print undefined On the other hand console.log(n[0].Organizations) works fine. What am I doing wrong? Can I not use x instead of Organizations?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When attempting to access data from an object with a variable, you can use bracket notation instead of dot notation.

So for you, you can do

const n = this.prac
const x = this.oa
console.log(x)
console.log(n[0][x])

Which should result in the value you're looking for.

I found this wonderful answer here How can I access and process nested objects, arrays or JSON? that gives more details and background on why this works.

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!