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

227
Views
Cómo hacer referencia a objetos anidados con "-" en el nombre

Tengo problemas para referirme a cualquier variable con "-" en el nombre de la variable. Siento que la respuesta es algo muy simple, pero no puedo resolverlo.

Por ejemplo

 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" }

para referirse a un elemento, los siguientes trabajos

 console.log(headers.server)

Pero lo siguiente no funciona porque javascript no reconoce - . ¿Cómo me refiero a x-mbx-used-weight-1m en este caso?

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

Puedes ver que no se reconoce en JSFiddle

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

0

Debe utilizar corchetes y comillas:

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