I encountered an issue while searching through a JSON array filled with Google fonts. The fonts are structured by family -> files -> filename. However, I noticed that sometimes the filename is saved as a number. For example (refer to the bottom of the array under "files" labeled "100"):
"family": "Roboto",
"variants": [
"100",
"100italic",
"300",
"300italic",
"regular",
"italic",
"500",
"500italic",
"700",
"700italic",
"900",
"900italic"
],
"subsets": [
"cyrillic",
"cyrillic-ext",
"greek",
"greek-ext",
"latin",
"latin-ext",
"vietnamese"
],
"version": "v30",
"lastModified": "2022-09-22",
"files": {
"100": "http://fonts.gstatic.com/s/roboto/v30/KFOkCnqEu92Fr1MmgWxPKTM1K9nz.ttf",
"regular": "http://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Me5WZLCzYlKw.ttf"
While iterating through the JSON array, I can easily reference the font file named "regular", but I am unsure how to access the file identified as "100" since numbers cannot be used as variables.
$.getJSON('https://www.googleapis.com/webfonts/v1/webfonts?key=mykey', function(response) {
var items = response.items;
items.forEach(function(fontitem){
if (fontitem.family == "Roboto") {
alert(fontitem.files.$100); //doesn't work
alert(fontitem.files.regular); //works
return;
}
});
});
alert(fontitem.files.$100); //doesn't work while
alert(fontitem.files.regular); //works