Sikau

JavaScript · Day 61 · about 25 min

More string tools

Slice, split, join and replace.

Text, cut and stitched

Real apps juggle text all day: cutting out a first name, splitting a list of tags, tidying phone numbers. Strings have a toolbox of methods for exactly this.

Cutting and searching

const city = "Kathmandu";
console.log(city.slice(0, 5));
console.log(city.slice(-4));
console.log(city.includes("man"));
console.log(city.startsWith("Kath"));
console.log(city.indexOf("d"));

The rest of this lesson

  • Splitting, joining, replacingexplain
  • Cleaning real-world textexplain
  • Predict the outputpredict
  • Slice and splitpredict
  • Your turnwrite code
  • Challengechallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript