Using IndexOf in Pas2JS

Top 

Example code : Using IndexOf in Pas2JS

procedure TForm1.W3Button2Click(Sender: TObject);

var

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

begin

  //Search an array for the item "Apple":

  WriteLn( fruits.indexOf("Apple") );    

 

  //Search an array for the item "Apple", starting the search at position 4:

  WriteLn( fruits.indexOf("Apple", 4) ); 

end;

Result is:

 

 The result will be: 2.  Meaning that "Apple" is located at position 2 in the array. 

The result will be: 6

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

JS output:

 var fruits = [];

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

      WriteLn(fruits.indexOf("Apple"));

      WriteLn(fruits.indexOf("Apple",4));