forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathisEmpty.as
More file actions
41 lines (32 loc) · 910 Bytes
/
isEmpty.as
File metadata and controls
41 lines (32 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package utils.object {
/**
Determines if object contains no value(s).
@param obj Object to determine if empty.
@return Returns <code>true</code> if object is empty; otherwise <code>false</code>.
@example
<code>
var testNumber:Number;
var testArray:Array = new Array();
var testString:String = "";
var testObject:Object = new Object();
trace(ObjectUtil.isEmpty(testNumber)); // traces "true"
trace(ObjectUtil.isEmpty(testArray)); // traces "true"
trace(ObjectUtil.isEmpty(testString)); // traces "true"
trace(ObjectUtil.isEmpty(testObject)); // traces "true"
</code>
*/
public function isEmpty(obj:*):Boolean {
if(obj == undefined)
return true;
if(obj is Number)
return isNaN(obj);
if(obj is Array || obj is String)
return obj.length == 0;
if(obj is Object) {
for(var prop:String in obj)
return false;
return true;
}
return false;
}
}