JavaScript String Methods

console.log("Hash Bang Code ".length); // 16
console.log("Hash Bang Code".charAt(3)); // "h"
console.log("Hash Bang".concat(" Code")); // "Hash Bang Code"

console.log("Hash Bang Code".indexOf("H")); // 0
console.log("Hash Bang Code".lastIndexOf("g")); // 8
console.log("Hash Bang Code".search("a")); // 1

console.log("Hash Bang Code".startsWith("H")); // true
console.log("Hash Bang Code".endsWith("e")); // true
console.log("Hash Bang Code".includes("!")); // false

console.log("Hash Bang Code".match(/code/ig)); // ["Code"]
console.log("Hash Bang Code".replace(/hash bang/ig, "#!")); // "#! Code"

console.log("Hash Bang Code".padStart(3, "_")); // "__Hash Bang Code"
console.log("Hash Bang Code".padEnd(3, "_")); // "Hash Bang Code__"

console.log("Hash Bang Code".repeat(2)); // "Hash Bang CodeHash Bang Code"

console.log("Hash Bang Code".slice(10, 14)); // "Code"
console.log("Hash Bang Code".substring(10,14)); // "Code"
console.log("Hash Bang Code".split(" ")); // ["Hash", "Bang", "Code"]
console.log("Hash Bang Code".toLowerCase()); // "hash bang code"
console.log("Hash Bang Code".toUpperCase()); // "HASH BANG CODE"

console.log(" Hash Bang Code ".trim()); // "Hash Bang Code"
console.log(" Hash Bang Code ".trimStart()); // "Hash Bang Code "
console.log(" Hash Bang Code ".trimEnd()); // " Hash Bang Code"

console.log("Hash Bang Code ".bold()); // "<b> Hash Bang Code </b>"
console.log("Hash Bang Code ".link('https://www.hashbangcode.com/')); // "<a href=\"https://www.hashbangcode.com/\"> Hash Bang Code </a>"

 

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
1 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.