Golang strings.Index = JavaScript String indexOf()


Go strings.Index = JavaScript String.prototype.indexOf()

The following Go code (Run Online):

strings.Index("chicken", "ken")

is the same as the following JavaScript code (Run Online):

"chicken".indexOf("ken")

Moreover, Go strings.Contains = JavaScript String.prototype.indexOf() != -1

The following Go code (Run Online):

strings.Contains("seafood", "foo")

is the same as the following JavaScript code (Run Online):

"seafood".indexOf("foo") != -1

References:

[1]
[2]JavaScript String indexOf() Method
[3]func Index - Package strings - The Go Programming Language