我不知道为什么我无法访问 forEach
内的 allSubIABs
数组。
我可以很好地访问字符串 newCheckState
。
const newIABs = { ...this.state.iabs }
let allSubIABs = []
let newCheckState = 'asdasdasd'
console.log(typeof allSubIABs, allSubIABs)
Object.keys(newIABs).forEach(firstLevelIABCode => {
console.log(newCheckState)
console.log(typeof allSubIABs, allSubIABs)
let allSubIABs = allSubIABs.concat(newIABs[firstLevelIABCode].children)
})
输出:
object []
asdasdasd
undefined undefined
Uncaught TypeError: Cannot read property 'concat' of undefined
最佳答案
您的问题是回调中的 let
声明隐藏了外部 allSubIABs
声明。只需摆脱那个 let
即可。
关于javascript - 为什么我无法在 javascript 中访问 forEach() 内的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47269166/