I am making a re-useable drop menu component.
const objectInfo = {firstName:"", lastName:"", age:""}
const objectError = { firstNameError: false, lastNameError: false, ageError: false, }
And I am going to pass the objectError to the drop menu component to set the error to true if the related element is an empty string.
But the problem is I don't know the logic how to map through those elements and match them to the specific position.
CodePudding user response:
just loop through object keys
const objectError ={}
for(key in objectInfo){
objectError[key] = !objectInfo[key]
}