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

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

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

html - jQuery UI Sortable - Remove placeholder after item is dropped -