Javascript String Methods: A Cheat Sheet for Developer
4 min readJun 10, 2022
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