Wednesday, September 12, 2018

JavaScript - Built in Functions - String Functions

In JavaScript, a string is treated as an array. The following are some commonly used string functions:

var myString = "  a quick brown fox  ";
console.log(myString);
console.log(myString.length);
console.log(myString[12]);
console.log(myString.charAt(12));
console.log(myString.concat("jumped over the lazy dog"));
console.log(myString.concat("jumped over the lazy dog").toUpperCase());
console.log(myString.concat("jumped over the lazy dog").toLowerCase());
console.log(myString.concat("jumped over the lazy dog").split(" "));
console.log(myString.trim());
console.log(myString.slice(4,12));


Console Output:

  • "  a quick brown fox  "
  • 21
  • "o"
  • "o"
  • "  a quick brown fox  jumped over the lazy dog"
  • "  A QUICK BROWN FOX  JUMPED OVER THE LAZY DOG"
  • "  a quick brown fox  jumped over the lazy dog"
  • ["", "", "a", "quick", "brown", "fox", "", "jumped", "over", "the", "lazy", "dog"]
  • "a quick brown fox"
  • "quick br"




Practice at:



Refer:



No comments:

Post a Comment