The indexOf() method with Array



The indexOf() method returns the position of the first occurrence of a specified value in a array.
The indexOf() method is case sensitive!
Note: This method returns -1 if the string value to search for never occurs.
Pas2JS pascal source code
var a: array of string; s: string; begin if a.IndexOf('J' + s) >= 0 then Writeln('bug1'); a.Add('J'); if a.IndexOf('J' + s) <> 0 then Writeln('bug2'); s := 'j'; if a.IndexOf('J' + s) >= 0 then Writeln('bug3'); a.Add('Jj'); Writeln(a.IndexOf('J' + s)); // 1 s := ''; Writeln(a.IndexOf(s + 'j')); // -1 s := 'J'; Writeln(a.IndexOf(s + 'j')); // 1 WriteLn('----------'); a.Add('Hello world'); Writeln(a.IndexOf('Hello')); // -1 Writeln(a.IndexOf('Hello World')); // -1 Writeln(a.IndexOf('Hello world')); // 2 Writeln(a.IndexOf('World')); // -1 Writeln(a.IndexOf('world')); // -1