In JavaScript, it is usually difficult to determine whether a variable is an array, because
VaRA=[];
Alert (TypeofA=== 'Object');//True
The common practice is to judge
A. Constructor===Array//True
However, this method has a problem. If an array comes from another frame, its constructor will be another object.
Yui uses the following method:
Isarray:Function(O ){
If(O ){
ReturnL. isnumber (O. length)&&L. isfunction (O. splice );
}
Return False;}
In short, it is to judge whether the variable has the Length attribute and whether there is a splice method. Unfortunately, this method can use an object to forge an array.
Google's Mark Miller found that the following method can be used to obtain an array of variables in a simple and reliable manner:
Object. Prototype. tostring. Apply (value)=== '[Object array]'
Simple & Easy: I have already added this method to D-u. I believe other libraries will gradually adopt this method.
From the miller Device