How to find a substring position in a string ? something like indexOf in js

You can also use regular expression

~r/#{Regex.escape(substring)}/
|> Regex.scan(string, return: :index)

This returns the indices and lengths of all matching parts as [[{index1, length1}], [{index2, length2}], ...]