Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda