pm.response.json() will most likely produce a JavaScript object, not an array.
It’s an important distinction as an ForEach loop only works with arrays.
Therefore, you need to wrap a for loop around your test.
In the following example(s). I have created an array, and I’ve included examples of both loops. I suspect you will need to use the first example.
var array =
[{
"id": 377,
"forename": "Forename 493068",
},
{
"id": 376,
"forename": "Forename 493067",
},
{
"id": 375,
"forename": "Forename 123456",
}];
console.log(typeof(array)); // array is a special type of "object"
pm.test("Array", () => {
pm.expect(array).to.be.an("array"); // change this to object and it will fail
});
for (let i = 0; i < array.length; i++) {
var id = array[i].id;
// console.log(id);
pm.test(`for loop expect ${id} to be an number`, () => {
pm.expect(id).to.be.an("number");
});
};
array.forEach(line => {
var id = line.id;
pm.test(`forEach loop expect ${id} to be an number`, () => {
pm.expect(id).to.be.an("number");
});
});