In JavaScript, there isn’t a built-in method to directly capitalize strings, but it’s straightforward to implement using basic string manipulation methods.
In JavaScript, you’ve got a few ways to concat strings.
In JavaScript, we convert a string to lowercase with the .toLowerCase() method.
.toLowerCase()
Use replace() with a regular expression.
replace()
How to: Using substring method: let text = "JavaScript is awesome!"; let extracted = text.substring(0, 10); console.log(extracted); // Output: JavaScript Using slice method: let text = "JavaScript is awesome!"; let sliced = text.slice(-9, -1); console.log(sliced); // Output: awesome Using substr method (deprecated): let text = "JavaScript is awesome!"; let substrd = text.substr(11, 7); console.log(substrd); // Output: awesome Deep Dive Extracting substrings isn’t new – it’s as old as programming itself. The substring and slice methods in JavaScript are tools from the 1990s, part of the language’s initial feature set.
JavaScript keeps it simple with the .length property.
.length
In JavaScript, string interpolation is often done using template literals.
Imagine you’ve got a string that’s wrapped in double quotes, like ""Hello, World!"" and you want the pure, unquoted text.
""Hello, World!""
In JavaScript, String.prototype.replace() is the go-to.
String.prototype.replace()
To start, you can create a simple regex pattern and use it to find matches in a string.