I’m reading Eloquent JS and I tried using the template literals, but instead of getting the variable I’m getting the chars ${variable} as part of the string. As far as I can tell I’m using the template literals exactly as supposed to.
I’ll add the full code at the end.
I have this data structure:
SCRIPTS = [ { name: "Adlam", ranges: [[125184, 125259], [125264, 125274], [125278, 125280]], direction: "rtl", year: 1987, living: true, link: "https://en.wikipedia.org/wiki/Fula_alphabets#Adlam_alphabet" }, ...
and I tried iterating over the name property:
for (let item in SCRIPTS) {
console.log('${item} name is: ${SCRIPTS[item].name}');
}
running on the chrome console I get a line “${item} name is: ${SCRIPTS[item].name}”, without the actual variables.
What am I doing wrong?
Full code:
let SCRIPTS = [
{
name: "Adlam",
ranges: [[125184, 125259], [125264, 125274], [125278, 125280]],
direction: "rtl",
year: 1987,
living: true,
link: "https://en.wikipedia.org/wiki/Fula_alphabets#Adlam_alphabet"
},
{
name: "Caucasian Albanian",
ranges: [[66864, 66916], [66927, 66928]],
direction: "ltr",
year: 420,
living: false,
link: "https://en.wikipedia.org/wiki/Caucasian_Albanian_alphabet"
},
{
name: "Ahom",
ranges: [[71424, 71450], [71453, 71468], [71472, 71488]],
direction: "ltr",
year: 1250,
living: false,
link: "https://en.wikipedia.org/wiki/Ahom_alphabet"
},
]
for (let item in SCRIPTS) {
console.log('${item} name is: ${SCRIPTS[item].name}');
}