Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda