Additional String Methods
Review old string methods and learn the new ones introduced in ES6.
We'll cover the following...
There are many methods that we can use against strings. Here’s a list of a few of them:
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
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"
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"