I'm using react and I have state like this
this.state = {
form: {
name: {required: true, filled: false, value: ''},
age: {required: true, filled: false, value: ''},
dob: {required: false, filled: false, value: ''}
}
}
I want to check if every form field has been filled, I tried this
const formValid = Object.keys(this.state.form).filter(o=>{
return o.required
}).every(o=> {
return o.filled!==null && o.filled!==''
})
I know this is wrong because Object.keys just return the key, I wish the state is array it will make my life much easier, but what if I don't want to change the structure of the state? How do I do it?