O'Reilly logo

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond by JD Isaacks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Consider this

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() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required