I get results from Ajax call and want to push it to an array as objects;
This is my try:
var myList = [""];
$.ajax({
url: 'list.json',
dataType: 'json',
success: function (data) {
for (var i = 0; i < data.length; i++) {
myList.push({
id: data[i].id,
text: data[i].text
});
}
console.log(myList);
}
});
The output I get is:
["",Object, Object, Object, ...]
I'm wondering how can I get the output like this:
["", {id:"id", text:"text"}, {id:"id", text:"text"}, ...]
JSON.stringify()