Chapter 4: New String Methods — String.prototype.*
by Aurelio de Rosa
In my previous chapter on ES6 array methods, I introduced the new methods available in ECMAScript 6 that work with the Array
type. In this tutorial, you'll learn about new ES6 methods that work with strings: String.prototype.*
We'll develop several examples, and mention the polyfills available for them. Remember that if you want to polyfill them all using a single library, you can employ es6-shim by Paul Miller.
String.prototype.startsWith()
One of the most-used functions in every modern programming language is the one to verify if a string starts with a given substring. Before ES6, JavaScript had no such function, meaning you had to write it yourself. The following code shows ...
Get Practical ES6 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.