함수 is array()

Jmnote (토론 | 기여)님의 2014년 11월 7일 (금) 17:20 판 (→‎같이 보기)
is_array
isArray
  • (boolean) Determine whether the argument is an array

1 C#

public static bool is_array(object obj) 
{
  return obj.GetType().IsArray;
}
int [] array = {1,2,3,4};
Console.WriteLine("Is this type an array? {0}", array.GetType().IsArray);

2 JavaScript

function is_array(input){ return typeof(input)=='object'&&(input instanceof Array); }
var bar = 1;
var foo = [1];
console.log(is_array(bar)); // false
console.log(is_array(foo)); // true

3 jQuery

var bar = 1;
var foo = [1];
console.log($.isArray(bar)); // false
console.log($.isArray(foo)); // true

4 Objective-C

// NSArray or NSMutableArray → true
-(bool)is_array:(NSObject*)obj {
  return [obj isKindOfClass:[NSArray class]];
}

5 PHP

// true
echo is_array( array(1, 2, 3) );

// false
echo is_array( '1, 2, 3' );

6 VBA

Function IsCollection(ByVal obj) As Boolean
    On Error Resume Next
    Dim element As Variant
    IsCollection = True
    For Each element In obj
        If Err Then IsCollection = False
        Exit For
    Next
    Err.Clear
End Function

Dim col As New Collection
Dim str As String
    
MsgBox IsCollection(col) 'True
MsgBox IsCollection(str) 'False

7 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}