I have an JavaScript object with keys and values. I need to validate that object's values, and if it contains value 'empty', I want to give an alert. I want to give alert only once even if there were multiple 'empty' values.
I tried like this;
data = [
{first_name: 'John', last_name: 'Doe'},
{first_name: 'Kiki', last_name: 'empty'},
{first_name: 'Kim', last_name: 'empty'},
]
data.forEach(function(value){
if(value.last_name == 'empty'){
alert('Please fill all the field');
return false;
}
});
This could validate the value, but it's giving alert twice.
I want to show alert only once. How can I do this?