配列の長さを得る

Contents

出力結果

2

プログラム例

JavaScript

let array = [1, 2, 3];
console.log(array.length);

Perl

my @array = (1, 2, 3);
my $len = $#array+1;
print $len."\n";

PHP

<?php
$array = [1, 2, 3];
print count($array)."\n";

Python

array = [1, 2, 3]
print(str(len(array)))

Ruby

array = [1, 2, 3]
print(array.length.to_s + "\n")