我有一个类似下面的函数,我想遍历数组并根据比较返回一些值,
function genBorder(old , newer)
{
var temp = "blue";
old.forEach( function(x) {
var oldy = x.price;
var oldq = x.quantity;
if(oldy == newer.price)
{
if(oldq < newer.quantity)
{
var temp = "green";
console.log("green");
return false;
}
else
{
var temp = "red";
return false;
}
}
});
return temp;
}
即使满足条件且console.log("green");
正常运行,上述函数也始终返回蓝色值