Web Dev Roadmap for Beginners (Free!): https://bit.ly/DaveGrayWebDevRoadmap
I was checking for empty Arrays wrong... and in this tutorial, I'll show you how to check for empty arrays as well as undefined and null values... and avoid the cannot read property of undefined error!
Subscribe https://bit.ly/3nGHmNn
How to check for an empty array in JavaScript:
(00:00) Intro
(00:05) Overview
(00:38) Array length property
(01:08) A common mistake
(02:10) How to avoid this mistake
(02:29) There is a better way
(02:59) The optional chaining operator
(03:46) How to check object properties
(05:54) Use optional chaining and null coalescing together
(07:00) But is it really an array?
References:
MDN Optional Chaining: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
MDN Null Coalescing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator
Follow Me:
Twitter: https://twitter.com/yesdavidgray
LinkedIn: https://www.linkedin.com/in/davidagray/
Blog: https://yesdavidgray.com
Reddit: https://www.reddit.com/user/DaveOnEleven
Was this tutorial about how to checking for empty arrays with the optional chaining operator helpful? If so, please share. Let me know your thoughts in the comments.
#empty #array #javascript