Using Insert to add one item at specific index to an array in Pas2JS
Example code : Using Insert to add one item at specific index to an array in Pas2JS
var
fruits : array of String = ["Banana", "Orange", "Apple", "Mango", "Banana", "Abacate", "Apple"];
begin
fruits.Insert(2, "Lemon");
for var Index := Low(fruits) to High(fruits) do
WriteLn( fruits[Index] );
Banana
Orange
Lemon
Apple
Mango
Abacate
-----------
JS output:
var fruits = [];
var fruits = ["Banana","Orange","Apple","Mango","Banana","Abacate","Apple"].slice();
var Index = 0;
$ArrayInsert(fruits,2,"Lemon","");
var $temp24;
for(Index = 0,$temp24 = fruits.length;Index<$temp24;Index++) {
WriteLn($DIdxR(fruits,Index,""));
}