...

/

Additional String Methods

Additional String Methods

Review old string methods and learn the new ones introduced in ES6.

There are many methods that we can use against strings. Here’s a list of a few of them:

  1. indexOf()

Gets the position of the first occurrence of the specified value in a string.

Press + to interact
const str = "this is a short sentence";
console.log(str.indexOf("short"));
// Output: 10
  1. slice()

Pulls a specified part of a string as a new string.

Press + to interact
const str = "pizza, orange, cereals"
console.log(str.slice(0, 5));
// Output: "pizza"
  1. toUpperCase()

Turns all characters of a string to uppercase.

Press + to interact
const str = "i ate an apple"
console.log(str.toUpperCase());
// Output: "I ATE AN APPLE"
...