I have a JSON file that contains the following: [{name:joe,number:4},{name:ralph,number:76}]
Simply put, I'm trying to create a function that returns that as an array:
function createArray(){
x = $.getJSON("/names.json", function(json) {
var myArray = [];
$.each(json, function() {
myArray.push(json);
});
return myArray;
});
return x;
}
This is not working, I'm not sure what part of it doesnt make sense
alert(json);before thevar myArray ..., does it tell you it's an object? Or is there an error server side perhaps?console.log(json)in the callback