2👍
✅
Adding to what @user1538301 answered, if you want to know which properties fail to fulfill the criteria is possible to use Array::filter
the following way:
const missingProperties = Object.values(this.currentObjectData)
.filter(data => objectData.report_type);
if(missingProperties.length > 1) {
// Do something with the missing properties
} else {
EventBus.$emit("allObjectsAreValidated");
}
Also a few things I noticed in the code:
-
this.objectData
: I’m assuming your intention is not to use a variable from the object but rather the parameter of the anonymous function, soobjectData
would be the right variable. -
!this.objectData.report_type || this.objectData.report_type === ""
: An empty string is a falsy value so when evaluated as bool is equivalent to false. (More info: FreeCodeCamp)
2👍
Use Array.prototype.every
Try:
const allObjectsMatch = Object.values(this.currentObjectData).every(
value => /*return a boolean if they value matches*/
);
allObjectsMatch && EventBus.$emit("allObjectsAreValidated");
Source:stackexchange.com