Array length

1 개요[ | ]

len
length
count
  • 배열의 길이

2 Bash[ | ]

systems=("Solar System" "Alpha Centauri" "Barnard's Star")
echo ${#systems[@]}
# 3
echo ${#systems[*]}
# 3

3 C#[ | ]

string[] weekDays2 = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
MessageBox.Show(weekDays2.Length);
// shows 7

4 Go[ | ]

package main

import "fmt"

func main() {
    fruits := []string{"apple", "banana", "mango"}
    fmt.Println( len(fruits) ) // 3
}

5 Java[ | ]

String[] weekDays2 = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
System.out.println(weekDays2.length);
// shows 7

6 JavaScript[ | ]

var weekDays2 = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ];
document.write(weekDays2.length);
// shows 7

7 Objective-C[ | ]

NSArray *weekDays2 = [NSArray arrayWithObjects:@"Sun", @"Mon", @"Tue", @"Wed", @"Thu", @"Fri", @"Sat", nil];
NSLog(@"%lu", [weekDays2 count]);
// shows 7

8 Perl[ | ]

@nums = (1,2,3,4);
print scalar(@nums);
# shows 4

9 PHP[ | ]

$nums = [1,2,3,4];
echo count($nums);
// shows 4

10 POSIX Shell[ | ]

WEEKDAYS2="Sun Mon Tue Wed Thu Fri Sat"
echo $WEEKDAYS2 | tr ' ' '\n' | grep -cP '\S+'
# 7

11 Python[ | ]

nums = [1,2,3,4]
print len(nums)
# shows 4

12 R[ | ]

x <- c("apple","banana","orange")
cat( length(x) )
# 3
cat( length(diag(4)) )
# 16

13 Ruby[ | ]

nums = [1,2,3,4]
puts nums.size
# shows 4

14 같이 보기[ | ]

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