After making an ajax call to the server, I receive a JSON array in response. The format of the JSON array is as follows:
[{id:1,name:"somename"}, {id:5,name:"someanothername"}]
I am trying to iterate through this array using the following code snippet:
$.ajax({
url: "/Search/SearchNews",
type: "POST",
cache: true,
async: true,
data: data,
success: function (result) {
for (var i = 0; i < result.length; i++) {
console.log(result[i].name);
}
}
});
However, I encounter an issue where console.log(result.length)
returns undefined
.
Can someone help me figure out how to properly loop through this array?