for..in loops iterate over the entire prototype chain, which is virtually never what you want.
It means that using for..in will traverse the entire prototype chain, which is not a good way to implement it. Object.keys is recommended
formRules : {
name : true,
cardType: true,
certificateNo: true
},
formData : {
name : '' ,
certificateType: '' ,
certificateNo: ''
}
Original code
for ( const key in this .formData) {
if (! this .formData[key]) { this .formRules[key] = false ; valid = false }
if ( this .formData[key]) this .formRules[key] = true
}
Modified code
Object.keys( this .formData).forEach(key => {
if (! this .formData[key]) { this .formRules[key] = false ; valid = false }
if ( this .formData[key]) this .formRules[key] = true
})
Read More:
- How to Test whether the property value of each property in the object is not empty
- React error boundary (What You Should Know & How to Solve)
- If the request parameter is formdata, use the Ajax operation
- [Solved] Router Pinia error: getActivePinia was called with no active Pinia. Did you forget to install pinia
- Vue a page is mounted to send multiple requests at the same time, and the loading is processed uniformly
- ‘webpack dev server’ is not an internal or external command, nor is it a runnable program or batch file. Solution: error in cnpm run dev:
- [Vue warn]: Error in v-on handler: “TypeError: Object(…) is not a function“
- ERROR in [eslint] ESLint is not a constructor (How to Solve)
- [Solved] React Error: ReactDOM.render is no longer supported in React 18.
- Using for in loop complex data types (object and array) in ES6
- [Solved] Uncaught (in promise) Error: Avoided redundant navigation to current location:
- [Solved] Failed to execute ‘getRangeAt‘ on ‘Selection‘: 0 is not a valid index.“
- vue.config.js build Package UglifyJsPlugin to clear console and print console.log Error: `warnings` is not a supported option
- The date selector Report Null Error in element is cleared
- [Solved] Element Error: Error in render: TypeError: dateStr.match is not a function“
- JS async await Error: Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
- [Solved] Vue3 Install vuetify Error: Error: You cannot call “get” on a collection with no paths.
- [Solved] error ‘xxx‘ is never reassigned. Use ‘const‘ instead prefer-const
- [Solved] To install it, you can run: npm install –save core-js/modules/es.error.cause.js
- [Solved] Error in nextTick: “TypeError: undefined is not iterable