I'm not sure why i can't access the allSubIABs array inside forEach.
I can access the string newCheckState fine.
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)
})
Output:
object []
asdasdasd
undefined undefined
Uncaught TypeError: Cannot read property 'concat' of undefined
console.log( newIABS )orconsole.log( Object.keys( newIABS ) )? I'm asking only because I've never seen the spread operator used to create an Object, only to populate an Array.