"함수 is array()"의 두 판 사이의 차이

잔글 (Jmnote님이 다언어 is array() 문서를 함수 is array() 문서로 이동하면서 넘겨주기를 덮어썼습니다)
 
(사용자 2명의 중간 판 10개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류: 다언어]]
[[category: Array]]
[[category: Array]]
{{lowercase title}}
;is_array
;is_array
;isArray
;isArray
7번째 줄: 7번째 줄:
==C#==
==C#==
[[category: Csharp]]
[[category: Csharp]]
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
public static bool is_array(object obj)  
public static bool is_array(object obj)  
{
{
   return obj.GetType().IsArray;
   return obj.GetType().IsArray;
}
}
</source>
</syntaxhighlight>
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
int [] array = {1,2,3,4};
int [] array = {1,2,3,4};
Console.WriteLine("Is this type an array? {0}", array.GetType().IsArray);
Console.WriteLine("Is this type an array? {0}", array.GetType().IsArray);
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
[[category:JavaScript]]
[[category:JavaScript]]
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
function is_array(input){ return typeof(input)=='object'&&(input instanceof Array); }
function is_array(input){ return typeof(input)=='object'&&(input instanceof Array); }
var bar = 1;
var bar = 1;
26번째 줄: 26번째 줄:
console.log(is_array(bar)); // false
console.log(is_array(bar)); // false
console.log(is_array(foo)); // true
console.log(is_array(foo)); // true
</source>
</syntaxhighlight>


==jQuery==
==jQuery==
[[category:jQuery]]
[[category:jQuery]]
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
var bar = 1;
var bar = 1;
var foo = [1];
var foo = [1];
console.log($.isArray(bar)); // false
console.log($.isArray(bar)); // false
console.log($.isArray(foo)); // true
console.log($.isArray(foo)); // true
</source>
</syntaxhighlight>


==Objective-C==
==Objective-C==
[[category: Objective-C]]
[[category: Objective-C]]
<source lang='objc'>
<syntaxhighlight lang='objc'>
// NSArray or NSMutableArray → true
// NSArray or NSMutableArray → true
-(bool)is_array:(NSObject*)obj {
-(bool)is_array:(NSObject*)obj {
   return [obj isKindOfClass:[NSArray class]];
   return [obj isKindOfClass:[NSArray class]];
}
}
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='php'>
<syntaxhighlight lang='php'>
// true
echo is_array( array(1, 2, 3) );
echo is_array( array(1, 2, 3) );
# true
echo is_array( '1, 2, 3' );
# false
</syntaxhighlight>


// false
==Ruby==
echo is_array( '1, 2, 3' );
[[category: Ruby]]
</source>
<syntaxhighlight lang='ruby'>
puts [1, 2, 3].kind_of?(Array)
# true
puts '1, 2, 3'.kind_of?(Array)
# false
</syntaxhighlight>


==VBA==
==VBA==
[[category: VBA]]
[[category: VBA]]
<source lang='vb'>
<syntaxhighlight lang='vb'>
Function IsCollection(ByVal obj)
Function IsCollection(ByVal obj) As Boolean
     On Error Resume Next
     On Error Resume Next
     Dim element As Variant
     Dim element As Variant
70번째 줄: 78번째 줄:
End Function
End Function


Dim col As New Collection
'Dim col As New Collection
Dim str As String
'Dim str As String
   
'MsgBox IsCollection(col) 'True
MsgBox IsCollection(col) 'True
'MsgBox IsCollection(str) 'False
MsgBox IsCollection(str) 'False
</syntaxhighlight>
</source>


==같이 보기==
==같이 보기==
*[[is_string]]
*[[is_string]]
*[[is_instance]]
*[[is_instance]]
*[[trace]]

2023년 10월 7일 (토) 19:21 기준 최신판

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 같이 보기[ | ]

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