Bro ... JavaScript sucks! I just spend half an hour trying to figure out why I couldn't push to an array ...

I have an object `b`, I check `hasOwnProperty` for my array `b`, I check `typeof a.b != 'object'`, and it all passes ... but my push kept failing!

Then, I `console.log(a.b)`, and, lo and behold, my `a.b` that exists as a type `object` is `==null` 😡

Fine! I'll check it three ways!

`if(!a.hasOwnProperty('b') || typeof a?.b != 'object' || !a.b) a.b = []`

There! I did it! 🤦‍♂️

Reply to this note

Please Login to reply.

Discussion

No replies yet.