How to verify a value in anywhere of the Array

Hi ,

I want to verify whether either 0th or 1st value in below is equal to ‘AF’

“validationResultErrors”: ,
“errorKeys”: ,
“data”: [
{
“id”: “cd367fba-f943-e911-a817-005056a23fb6”,
“isoNumeric”: “004”,
“name”: “Afghanistan”,
“isoA2”: “AF”
},
{
“id”: “cf367fba-f943-e911-a817-005056a23fb6”,
“isoNumeric”: “008”,
“name”: “Albania”,
“isoA2”: “AL”
},

…etc.

I used below code.

var i = 0
var jsonArray = pm.response.json();
pm.test(“Verify Received relevant Country List’”, function () {
for(i; i<jsonArray.data[i].length;i++){
pm.expect(jsonArray.data[i].isoA2).is.to.equal(“AF”)
}
});

This is working and Pass. But i just changed the is.to.equal(“Hello”) and still it gets Pass.
So it seems my code is incorrect.

Could u please help me on this?

You can loop through the array the way I did below. I think that should work. Give it a shot.

let jsonData = pm.response.json()

for (const ctyAbv of jsonData.data) {
pm.test(‘isoA2 expected value’, function () {
pm.expect(ctyAbv.isoA2).to.eql(‘AF’);
});
}