Strings are half of practical programming โ parsing input, formatting output, cleaning data. These 15 methods cover it.
const s = " Anna University Plus ";
s.trim() // "Anna University Plus"
s.toLowerCase() // for case-insensitive compares
s.includes("Univ") // true
s.startsWith("Anna") // true (after trim!)
s.indexOf("Plus") // position or -1
s.slice(0, 4) // "Anna" โ also negative: s.slice(-4)
s.replace("Plus", "Pro") // first match
s.replaceAll(" ", "-") // every match
s.split(" ") // โ array of words
["a","b"].join("-") // "a-b" โ split's inverse
s.charAt(0) / s[0] // single char
"5".padStart(3, "0") // "005" โ invoice numbers
"ab".repeat(3) // "ababab"
s.at(-1) // last char (modern)
`${name} scored ${marks}` // template literal โ the 15th "method"The interview trio
- Reverse:
s.split("").reverse().join("") - Capitalize:
s[0].toUpperCase() + s.slice(1) - Word count:
s.trim().split(/\s+/).length
Practice on the judge โ three problems are pure string manipulation.