I am trying to create an array from a json file using this:
<script type="text/javascript">
var stores = [];
$.getJSON('js/locations.json', function(data) {
$.each(data, function(key, value) {
stores.push("<option value="+key+">"+value+"</option>");
});
});
</script>
But the array appears to be empty when I call it. The json file looks like this:
{
'1' : 'Store 1',
'2' : 'Store 2',
'3' : 'Store 3'
}
If anyone could tell me why its not working it would be most appreciated. Thanks.
Try other json file content. For example this:
{
“one”: “Singular sensation”,
“two”: “Beady little eyes”,
“three”: “Little birds pitch by my doorstep”
}
Good luck 😉