Dynamic Array of Integer (Length, SetLength methods)



Dynamic Array of Integer / Dynamic array of array of Integer
Pas2JS pascal source code
var a: array of Integer; i: Integer; begin Writeln(Length(a)); // 0 a := New Integer[3]; Writeln(Length(a)); // 3 for i := Low(a) to High(a) do a[i] := i * i; a.SetLength(4); Writeln(a.Length); // 4 WriteLn('--------------'); for i := a.Low to a.High do Writeln(a[i]); // 0, 1, 4, 0 { OUTPUT DISPLAY a[0]; // 0 a[1]; // 1 a[2]; // 4 a[3]; // 0 }
Pas2JS pascal source code
var a : array of array of Integer; i, j : Integer; begin a.SetLength(3); for i:=a.Low to High(a) do begin a[i].SetLength(4); for j:=Low(a[i]) to a[i].High do begin a[i][j]:=(i+1)*10+j; end; end; for i:=0 to 2 do begin for j:=0 to 3 do WriteLn(a[i][j]); WriteLn(''); end; { 10,11,12,13 20,21,22,23 30,31,32,33 }