New String and Array Methods

We will learn about the addition of new string and array methods (static and prototype) in this lesson.

With the introduction of ES2015, many static and prototype methods were added to JavaScript. Even if several methods are not directly relevant to React, they are still very powerful.


String methods

In the past, we had to use indexOf() or regular expressions for operations such as checking if a value was present in a string or whether the string starts or ends with a specific value. With ES2015, the string data type has its own methods to do these checks:

string.includes(value);
string.startsWith(value);
string.endsWith(value);

A Boolean value is returned by the function in each of these — meaning either true or false. Go ahead and execute the code snippet below to visualize the working of these string methods.

Get hands-on with 1200+ tech skills courses.