함수 is array()

Jmnote (토론 | 기여)님의 2016년 1월 29일 (금) 18:29 판 (→‎PHP)
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

echo is_array( array(1, 2, 3) );
# true
echo is_array( '1, 2, 3' );
# false

6 Ruby

puts [1, 2, 3].kind_of?(Array)
# true
puts '1, 2, 3'.kind_of?(Array)
# false

7 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

8 같이 보기