aBloomer aBloomer - 17 days ago 9
Javascript Question

Why my code still will return true?

Below is my code

test.map((value, index) => {
console.log(value);
if(value.customer_mobile) {
alert(index + 'fail');
return false;
}

if(value.customer_email) {
alert(index + 'fail');
return false;
}
})

return true;


I run the code from above and it will return true even if
customer_mobile
is false. Why?

Answer

Try this:

var flag = true;
test.map((value, index) => {
    console.log(value);
    if(customer_mobile) {
        alert(index + 'fail');
        flag = false;
    } 

    if(customer_email) {
        alert(index + 'fail');
        flag = false;
    }
});

return flag;
Comments