JavaScript String Methods Cheatsheet — Complete Reference

All JS string methods: split, trim, replace, includes, startsWith, padStart, repeat, template literals, regex.

Common String Methods

MethodExampleResult
.length"hello".length5
.trim()" hi ".trim()"hi"
.toUpperCase()"hi".toUpperCase()"HI"
.toLowerCase()"HI".toLowerCase()"hi"
.includes()"hello".includes("ell")true
.startsWith()"hello".startsWith("he")true
.endsWith()"hello".endsWith("lo")true
.indexOf()"hello".indexOf("l")2
.slice()"hello".slice(1, 3)"el"
.replace()"hi hi".replace("hi","yo")"yo hi"
.replaceAll()"hi hi".replaceAll("hi","yo")"yo yo"
.split()"a,b,c".split(",")["a","b","c"]
.repeat()"ha".repeat(3)"hahaha"
.padStart()"5".padStart(3,"0")"005"
.at()"hello".at(-1)"o"

Template Literals

const name = "World";
`Hello, ${name}!`                  // "Hello, World!"
`Multi
line`                               // Works!
`Result: ${2 + 3}`                  // "Result: 5"

Regex with Strings

// Test a pattern
/^\d+$/.test("123")                  // true

// Match
"abc123".match(/\d+/)                // ["123"]

// Replace with regex
"hello world".replace(/\w+/g, w =>
  w[0].toUpperCase() + w.slice(1)
)                                    // "Hello World"

Need These Tools as an API?

TextForge API offers 20+ developer toolkit endpoints. Free tier: 50 requests/day.

Try TextForge API Free →

Related Tools