Find element index in array by value


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


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


Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)