Lesson 6. New string methods
After reading lesson 6, you will
- Know how to use String.prototype.startsWith
- Know how to use String.prototype.endsWith
- Know how to use String.prototype.includes
- Know how to use String.prototype.repeat
- Know how to use String.prototype.padStart
- Know how to use String.prototype.padEnd
None of these methods would be extremely difficult to implement, but they are tasks that are used enough to warrant inclusion in the standard library.
Let’s say you’re writing a function that tells the current time. Using an instance of the Date object, you can get the current hour and minutes with the getHours and getMinutes methods, respectively:
function getTime() { const date = new Date(); return date.getHours() ...
Get Get Programming with JavaScript Next 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.