Description ​
Returns the index (position) of an first instance of an item in an array
Arguments ​
any[]
- The array to search for the specified item inany
- The item you want to find the index of
Returns ​
number
- The index of the item in the array, or -1 if it isn't present
Example ​
msc
// Predefines
using Console;
using Array;
// EXAMPLE 1 - Illustration of Array.Length
string[] sentence = new string[5];
sentence[1] = "Sometimes";
sentence[2] = "I";
sentence[3] = "dream";
sentence[4] = "about";
sentence[5] = "cheese"; // CHEEEEEEEESE
//Find Index of the string "cheese"
number index = Array.IndexOf(sentence, "cheese");
//Print out the index
Console.WriteLine(index);