Javascript String Methods: A Cheat Sheet for Developer

Rahul Sharma (DevsMitra)
4 min readJun 10, 2022
Javascript String Methods: A Cheat Sheet for Developer | Rahul Sharma(DevsMitra)

Let’s understand javascript String functions and how to use them.

String.charAt()

Returns a string representing the character at the given index.

const str = "Hello World";
str.charAt(0); // "H"

String.charCodeAt()

Returns a number representing the UTF-16 code unit value of the character at the given index.

const str = "Hello World";
str.charCodeAt(0); // 72

String.concat()

Returns a new string containing the concatenation of the given strings.

const str = "Hello";
const str2 = " World";
str.concat(str2); // "Hello World"
console.log(`${str}${str2}`); // "Hello World"
console.log(str + str2); // "Hello World"

String.endsWith()

Returns true if the string ends with the given string, otherwise false.

const str = "Hello World";
str.endsWith("World"); // true

String.includes()

Returns true if the string contains the given string, otherwise false.

const str = "Hello World";
str.includes("World"); // true

--

--

Rahul Sharma (DevsMitra)
Rahul Sharma (DevsMitra)

Written by Rahul Sharma (DevsMitra)

I’m a technology enthusiast who does web development. Passionate to contribute to open-source projects and make cool products.