slice() and at() accept negative indexes counted from the end; substring() treats them as 0. Avoid the deprecated substr() and HTML wrappers such as bold(). Normalize input before comparing: é can be one code point or two.
| Purpose | Methods |
|---|---|
| Search | includes, startsWith, endsWith, indexOf, lastIndexOf, search |
| Extract | at (ES2022), charAt, slice, substring, split |
| Unicode | charCodeAt, codePointAt, normalize, isWellFormed, toWellFormed (ES2024) |
| Transform | toUpperCase, toLowerCase, toLocale...Case, repeat, concat |
| Trim and pad | trim, trimStart, trimEnd, padStart, padEnd |
| Regular expressions | match, matchAll, replace, replaceAll (Regular Expressions) |
const t = ' Hello, World '.trim();
console.log(t.at(-1), t.slice(-5, -1), t.indexOf('o'), t.lastIndexOf('o'), t.includes('World'));
console.log(t.split(', '), t.replaceAll('l', 'L'), t.padStart(15, '*'), 'ab'.repeat(3));
console.log('caf\u00e9' === 'cafe\u0301', 'caf\u00e9' === 'cafe\u0301'.normalize('NFC'));d Worl 4 8 true [ 'Hello', 'World' ] HeLLo, WorLd ***Hello, World ababab false true