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

260
Vistas
How to query a key via a variable?

I want to set the value of a JSON key by a variable to setCache with the star and then the function sets the key value in the JSON object cache.

I have code it how I think it makes sense, however I know this is wrong because star is not in the object.

I also thought of using template strings.

My code

var cache = {
    "capricorn": "this should be null",
    "aquarius": "null",
    "pisces": "null",
    "aries": "null",
    "taurus": "null",
    "gemini": "null",
    "cancer": "null",
    "leo": "null",
    "virgo": "null",
    "libra": "null",
    "scorpio": "null",
    "ophiuchus": "null",
    "sagittarius":"null"
}

function setCache(cache,star, value) {
    cache.star = value
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use the subscript ([]) operator to refer to a property using a variable:

cache[star] = value;
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