How to judge whether an array is empty?
2016-09-07 23:21
447 查看
Today I got an array from database.Before I used it,I first judged it.But I made a mistake,I used if(arr).I forgot an array is an object…
So if we want to judge whether an array is empty.take following measures:
or
So if we want to judge whether an array is empty.take following measures:
var arr=[]; if(arr == "")//object will change to string and an empty array returns "" { //code goes here }
or
var arr=[]; if(arr.length===0)//I recommend this for I do not want to use ==. ...
相关文章推荐
- How to display an empty row when the underlying dataset is empty
- How to judge if an iterator is used before.
- <boost -04>如何判断输入文件的类型在给定范围内?how to judge whether given file's extension is within list?
- How to find number of a specific integer in an array of Fixnums ruby
- How to initialize an array in C
- How to sensibly split an array around an object
- How do you test if an NSString is empty
- How to sort an array in Ruby to a particular order?
- How to sort an NSMutableArray with custom objects in it?
- How to limit an array of similar hashes to those that have more than one of the same key:value pair
- How to fix exchange 2010 alias is empty
- How To Determinate If An EMCPOWER Partition Is Valid For ASMLIB
- How to find variable is empty in shell script
- How To Remove An Empty ASM System Directory
- how to know whether an element has an class
- 转载:how to automate Microsoft Excel and return the values from a multi-cell range to an array
- How to resolve: The PsExec service running on ?????????????? is an incompatible version.
- How to Check if an Array Contains a Value in Java Efficiently?---reference
- How To Check Whether Physical Standby is in Sync with the Primary or Not?
- How to sort an array by its index? (SortIndex)