jquery - Check if array is not empty with length JavaScript -


i console.log(arr) shows [] console.log(arr.length) shows 0? it's confusing me, best way check if array contain something?

you can check if array empty checking length property:

if (arr.length === 0) {     // arr empty } 

or, check if contains items:

if (arr.length) {     // arr not empty } 

console.log(arr) show [] empty array. that's how shows , length property of 0 means there no items in array.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -