Commonly Used JavaScript String Functions and How To Use Them

Nazmul Huda
2 min readNov 2, 2020

The string is a mostly used datatype in all Programming Language. It consists of a number of characters that may be spaces, numbers and must be inside single or double-quotes. String function is used in JavaScript programming language to handle a string. Here I have discussed some of the most used string functions used in JavaScript Programming Language.

String.charAt(n)

This String Function Returns the Character in `n` Number position.

String.concat(“text1”, “text2”)

This String Function Join One or More String Together.

String.indexOf(“element”)

This String Function Searches (very first index) `element` from the existing string. If value finds returns `element` position number else returns `-1`.

String.lastIndexOf(“element”)

This String Function Searches (last index) `element` from the existing string. If value finds returns `element` position number else returns `-1`.

String.replace(existText, newText)

This String Function Searches existText form the string, if finds replace existText by the newText.

String.slice(start, end)

This String Function extracts parts of a string and returns the extracted part as a new string. Slice() method receives two parameters first one (required) where to start and the Second one (optional) where to end.

String.split(char/pattern)

This String Function divides string by the given parameter ‘char/pattern’ and returns an array.

String.includes(string/char)

This String Function check either the string contains specified `str/char` or not.

String.startWith(string/char)

This String Function check either the string start with specified `str/char` or not.

String.endsWith(string/char)

This String Function check either the string ends with specified `str/char` or not.

String.toLowerCase()

This string function returns the value of a string converted to lowercase.

String.toUpperCase()

This string function returns the value of a string converted to uppercase.

String.trim()

This string removes whitespaces from the start & ends of a string.

String.trimStart()

This string removes whitespaces from the start of the string.

String.trimEnd()

This string removes whitespaces from the end of the string.

--

--

Nazmul Huda

I'm a self-taught passionate Web Application Developer specialized in MERN Stack Web Development. JavaScript is my native programming language.