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?
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']
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"])