I am new to javascript and looking to do a for each loop on the below sample JSON string. I am trying to loop through each result item and see if the name = 'Error Code'. I have tried multiple different variations and the below snippet seems like it is correct but i cannot get it to show up in the console.
$.ajax({
url:'url',
dataType: 'json',
success: function (data) {
//handle the json response
for(let i = 0, l = data.results.length; i < l; i++) {
if (data.results.variable[i] == 'Error Code'){
console.log(data.results.value[i]);
}
}
},
});
{
"Count": 136,
"Message": "Results returned successfully.",
"SearchCriteria": "VIN:xxxxxxx",
"Results": [
{
"Value": "",
"ValueId": "",
"Variable": "Suggested VIN",
"VariableId": 142
},
{
"Value": "0",
"ValueId": "0",
"Variable": "Error Code",
"VariableId": 143
},
{
"Value": "",
"ValueId": "",
"Variable": "Possible Values",
"VariableId": 144
},
{
"Value": null,
"ValueId": "",
"Variable": "Additional Error Text",
"VariableId": 156
}
]
}