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

225
Vistas
How to refer to nested objects with "-" in the name

I am having trouble referring to any variables with "-" in the variable name. I feel the answer is something very simple but I can't figure it out.

For Example

var headers = {
  "content-type": "application/json;charset=UTF-8",
  "content-length": "261",
  "connection": "close",
  "date": "Fri, 01 Apr 2022 09:12:56 GMT",
  "server": "nginx",
  "vary": "Accept-Encoding",
  "x-mbx-uuid": "88911a02-ff75-4cc0-b8ef-1ea4ab0edabd",
  "x-mbx-used-weight": "10",
  "x-mbx-used-weight-1m": "10"
}

to refer to an element, the following works

console.log(headers.server)

But the following doesnt work because javascript doesn't recognise - . How do I refer to x-mbx-used-weight-1m in this case?

console.log(headers.x-mbx-used-weight-1m)

You can see it is not recognised in JSFiddle

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to use square brackets and quote marks:

headers["x-mbx-used-weight-1m"]
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