I have an object
const load={trolleyNo:"",trolleyItems:[],cartType:""}
I need to check there are no empty values in this object. The array in the object should not be empty, and neither should the strings. How can I do this?
I have an object
const load={trolleyNo:"",trolleyItems:[],cartType:""}
I need to check there are no empty values in this object. The array in the object should not be empty, and neither should the strings. How can I do this?
3
Answers
This Function returns true if any value in the object is empty:
I’d go over the values and use
every
to check the value’s length:you can write a function that iterates through the keys of your object and checks if they’re null and their length > 0: