Using Push in Pas2JS

Top 

Example code : Using Push to add more than one element to an array in Pas2JS

var

  fruits : array of String = ["Banana", "Orange", "Apple", "Mango", "Banana", "Abacate", "Apple"];

begin

  fruits.push("kiwi");

  for var Index := Low(fruits) to High(fruits) do

     WriteLn( fruits[Index] );

Banana

Orange

Apple

Mango

Banana

Abacate

Apple

Kiwi

Lemon

Pineapple

-----------------

 

JS output:

      var fruits = [];

      var fruits = ["Banana","Orange","Apple","Mango","Banana","Abacate","Apple"].slice();

      var Index = 0;

      fruits.push("Kiwi", "Lemon", "Pineapple");

      var $temp24;

      for(Index = 0,$temp24 = fruits.length;Index<$temp24;Index++) {

         WriteLn($DIdxR(fruits,Index,""));

      }