let data = {
"@type": "Movie",
"url": "/title/tt0443272/",
"name": "Lincoln",
"image": "https://m.media-amazon.com/images/M/MV5BMTQzNzczMDUyNV5BMl5BanBnXkFtZTcwNjM2ODEzOA@@._V1_.jpg",
"description": "As the American Civil War continues to rage, America's president struggles with continuing carnage on the battlefield as he fights with many inside his own cabinet on the decision to emancipate the slaves.",
"duration": "PT2H30M"
}
console.log(data.@type)
i have large json data from scrping but i don't know how to get value of data whose key is starting from "@"
how can i get value of @type
when i am use this method i got error :-
SyntaxError: Invalid or unexpected token
Just do console.log(data['@type'])
let data = {
"@type": "Movie",
"url": "/title/tt0443272/",
"name": "Lincoln",
"image": "https://m.media-amazon.com/images/M/MV5BMTQzNzczMDUyNV5BMl5BanBnXkFtZTcwNjM2ODEzOA@@._V1_.jpg",
"description": "As the American Civil War continues to rage, America's president struggles with continuing carnage on the battlefield as he fights with many inside his own cabinet on the decision to emancipate the slaves.",
"duration": "PT2H30M"
}
console.log(data['@type'])
You can access variable properties using the Bracket notation as well, like if its a key -> value:
let data = {
"@type": "Movie",
"url": "/title/tt0443272/",
"name": "Lincoln",
"image": "https://m.media-amazon.com/images/M/MV5BMTQzNzczMDUyNV5BMl5BanBnXkFtZTcwNjM2ODEzOA@@._V1_.jpg",
"description": "As the American Civil War continues to rage, America's president struggles with continuing carnage on the battlefield as he fights with many inside his own cabinet on the decision to emancipate the slaves.",
"duration": "PT2H30M"
}
console.log(data["@type"])
Variables in JavaScript can only start either a letter, dollar sign, or underscore.
When using an invalid variable name you cannot use dot notation and must use bracket notation
Invalid
data.@type
Correct
data['@type']