For in loop objects
For in looping objects, actually looping properties
obj = {
name: "No name",
sex: "man",
age: "24"
}
for(var i in obj) {
console.log(i) // name sex age
}
for(var i in obj) {
console.log(obj[i]) // No name man 24
}
For in loop arrays
For in loops through an array, but it loops through the index
arr = ["zhangsan","wangwu","lisi"]
for(var i in arr) {
console.log(i) //0 1 2
}
for(var i in arr) {
console.log(arr[i]) //zahngsan wangwu lisi
}
Read More:
- [Solved] Binding onclick event in JS: for loop: error uncaught typeerror: cannot set properties of undefined (setting ‘classname’)
- Module not found: Error: Can‘t resolve ‘core-js/modules/es.promise.js‘ in
- [Solved] Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension
- [Solved] This dependency was not found: * core-js/modules/es.error.cause.js in ./node_modules/_@babel_runtim
- Method of adding operation button for each line of data in DataGrid of easyUI
- [Vue warn]: Error in v-on handler: “TypeError: Object(…) is not a function“
- Module build failed: Error: Couldn’t find preset “es2015” relative to directory
- How to Test whether the property value of each property in the object is not empty
- Special JSON array of special bracket
- How to solve Uncaught (in promise) error in VUE?
- Error in created hook: “SyntaxError: Unexpected token u in JSON at position 0
- core-js/modules/es.error.cause.js [How to Solve]
- ERROR Error: [copy-webpack-plugin] patterns must be an array
- [Solved] Error in mounted hook: “Error: please transfer a valid prop
- [Solved] To install it, you can run: npm install –save core-js/modules/es.error.cause.js
- [Solved] AES encryption in ie11 results in an error (missing ‘)‘
- [Solved] Vue3 Error: Cannot use ‘in‘ operator to search for ‘path‘ in undefined
- Error in nextTick: “TypeError: Cannot set properties of undefined (setting ‘checked‘)“
- [Solved] Error in created hook: “SyntaxError: Unexpected token o in JSON at position 1“
- [Solved] vue watch Error: Error in callback for watcher “xxx“: “TypeError: Cannot read properties of undefined …