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

217
Views
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 answers
Answer question

0

You need to use square brackets and quote marks:

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!