if (!Array.isArray(array) || !array.length) { // array does not exist, is not an array, or is empty // ⇒ do not attempt to process array } or if (!array?.length) { // array or array.length are falsy // ⇒ do not attempt to process array }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter