This is my JavaScript function to check if a particular entry exists or not in an array, but this is always returning null even though there is a match
function getSupplierForId(supplierId) {
data.suppliers.forEach(x => {
console.log('Current item id : ' + x.id);
console.log('Requested supplier id : ' + supplierId);
console.log('Both ids are equal : ' + (x.id === supplierId));
if (x.id === supplierId) {
console.log(x);
return x;
}
});
return null;
}
This is my console output:
Why is it returning null always?