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
Post a Comment