← Back to TIL

JS String Methods

charAt()

The charAt() method of String values returns a new string consisting of the single UTF-16 code unit at the given index.

Syntax

charAt(index);

// Example
const car = "benz";
car.charAt(0); // 'b'

slice()

The slice() method of String values extracts a section of this string and returns it as a new string, without modifying the original string.

Firefox Docs 🔗

Syntax

slice(indexStart)
slice(indexStart, indexEnd)

// Example
const name = "hell boy"
name.slice(-1) = 'y'