Find element index in array by value

 Problem

I have an Array and want to get the index of the first occurrence (if any) of a specific element.



 Recipe


// Initialize the Array
let arr = ["one", "two", "three", "four"]
 
// Find first occurence of "two" (if any)
var location = arr.indexOf("two")

print(location!)
				


 Playground