In ESLint mode, for in will report an error when traversing the object, which can be solved as follows:
let val = { shu: [ 1 , 2 , 3 ]} ;
for (let item in val) {
if (val.hasOwnProperty(item)) {
console.log(item);
}
}
Because we should judge whether the object has its own properties (non-inheritance) before traversing an object. If the object is an empty object, then there is no need to traverse it to improve the efficiency of the code.
Read More:
- [Vue warn]: Error in render: “TypeError: Cannot read properties of undefined
- [Vue warn]: Error in render: “TypeError: Cannot read properties of undefined
- [Solved] error TS1086: An accessor cannot be declared in an ambient context
- [Solved] vue watch Error: Error in callback for watcher “xxx“: “TypeError: Cannot read properties of undefined …
- Error in nextTick: “TypeError: Cannot set properties of undefined (setting ‘checked‘)“
- [Solved] Cannot read properties of undefined (reading ‘propsData‘)“
- [Solved] ant design pro vue Startup Error: ERROR Failed to compile with 1 error 20:34:09 error in ./src/components/Num
- [Solved] Error in v-on handler “TypeError Cannot read properties of undefined (reading ‘resetFields‘)“
- Vue form validate error: Error in v-on handler “TypeError Cannot read properties of undefined (reading ‘indexOf‘)
- [Solved] component import error is declared in the statement of components
- [Solved] Binding onclick event in JS: for loop: error uncaught typeerror: cannot set properties of undefined (setting ‘classname’)
- uniapp [Vue warn]: Error in onLoad hook: “TypeError: Attempting to change the setter of an unconfigu
- [Solved] VUE Error: Error in mounted hook: “TypeError: Cannot read properties of undefined (reading ‘$on‘)“
- [Solved] Element form method Error: TypeError: Cannot read properties of undefined (reading ‘resetFields’)
- [Solved] error: Unexpected console statement (no-console)
- [Solved] Element form method resetfields() error: vue.runtime.esm.js?2b0e:1888 TypeError: Cannot read properties of undefined (reading ‘indexOf’)
- Solve the problem of repeatedly clicking the same route console in Vue to report an error
- If the request parameter is formdata, use the Ajax operation
- [Solved] JS Error: Uncaught SyntaxError: Illegal return statement
- [Solved] JS Error: Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘)