UNPKG

locutus

Version:

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

15 lines (14 loc) 512 B
export function HasPrefix(s, prefix) { // discuss at: https://locutus.io/golang/strings/HasPrefix // parity verified: Go 1.23 // original by: Kevin van Zonneveld (https://kvz.io) // example 1: HasPrefix('Gopher', 'Go') // returns 1: true // example 2: HasPrefix('Gopher', 'C') // returns 2: false // example 3: HasPrefix('Gopher', '') // returns 3: true s = s + ''; prefix = prefix + ''; return s.startsWith(prefix); }