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:
Practice at:
Refer:
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:
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
No comments:
Post a Comment