javascript - Using for-of / for each array of states to manipulate dom -


i wondering how automate below in kind of for-of way.

if want perform same test , action many specific states (not all), how go doing

var anarray = [firstname, lastname];  (anarray q){   if(this.state.q.length > 1 || this.state.q.length == 0){     document.getelementbyid(tostring(q)).classname="someclass";   }else{     document.getelementbyid(tostring(q)).classname="anotherclass";   } } 

in return:

return function(e) {   var state = {};   state[key] = e.target.value;   this.setstate(state, () => {      if(validate(this.state.dob)){       document.getelementbyid("dob").classname="inputyay";     }else{       document.getelementbyid("dob").classname="inputerr";     }      //firstname     if(this.state.firstname.length > 1 || this.state.firstname.length == 0){       document.getelementbyid("firstname").classname="inputyay";     }else{       document.getelementbyid("firstname").classname="inputerr";     }      //lastname     if(this.state.lastname.length > 1 || this.state.lastname.length == 0){       document.getelementbyid("lastname").classname="inputyay";     }else{       document.getelementbyid("lastname").classname="inputerr";     }    }   ); } 

ultimately check key of each state provided return function, cant head around how work validating different types of responses.

i appreciate either method understanding.

many :


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -