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

192
Views
Put special characters inside JavaScript variables

I got a json and it has special characters inside.

myJSON = "metadata": Object {
  "album-art": "album-art.png",
}

However - Variable declaration is not possible due to the special character "-".

const Variable = myJSON.album-art

Can I put it inside a variable?

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

0

Do this. There are two methods to access a property/method in a object. One is dot notation and the other is square bracket notation (example below)

const Variable = myJSON['album-art']

about 4 years ago · Juan Pablo Isaza Report

0

It's a better practice to use _ instead of -, but you can access the variable using myJSON["prop"]

myJSON = {
  "album-art": "album-art.png",
}

console.log(myJSON["album-art"])

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!