10 Things to Know About JavaScript String

10 Things to Know About JavaScript String

charAt(): charAt() is used to get the exact word in the desired index number of a string. For example if we say var river = “jamuna”; console.log(river.charAt(3)) it will show “u” as output.

charAt() Code
charAt() Output

concat(): concat()is used to merge two string to make one sentence. And newly made string doesn’t affect the original string.

concat() Code
concat() Output

includes(): includes() is widely used to check if the word is in the string or not. And It returns the truthy or falsy value.

includes() Code
includes() Output

indexOf(): indexOf()is used to find the position of a specific string in another string. And it returns the position value. It is widely used to know the index of a desired word in a string.

indexOf() Code
indexOf() Output

replace(): replace() is used to replace a specific word in a string. Either using different variables or directly. It is one of the most used methods of string.

replace() Code
replace() Output

slice(): slice()method is also an important method of string and it is used to extract/divide a portion of a string to make a new string without modifying the original string. And it is possible to set the boundary to slice the string with the slice method.

slice() Code
slice() Output

substr(): substr()method is used to cut the specific portion of a string. There are two ways to use it, either we can tell the starting index number until the end or we can define the boundary using starting and closing indexes.

substr() Code
substr() Output

toLowerCase(): toLowerCase() method is one of the most used methods. It is used to lowercase all the words in a string.

toLowerCase() Code
toLowerCase() Output

toUpperCase() : toUpperCase() method is also one of the most widely used methods. It is used to uppercase all the words in a string.

toUpperCase() Code
toUpperCase() Output

trim(): trim() method is used to remove all the unexpected white space from the beginning and the ending sides of a string. It also removes the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.) from both sides.

trim() Code
trim() Output

Happy Coding!!!

Programmer || Web Developer || Learner || Practitioner

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store