16 Topics About JavaScript String

Rabiul Islam
4 min readMay 5, 2021

Anything wrapped between quotes is called String. Below I will talk about 16 topics about javascript string how it works and uses it. So let’s starts:

  1. chartAt(): In this method, you can easily found the word which you want to see from the string.For example:
const first= “He is an honest person”;const position= 4;console.log(first.charAt(position));//output : sconst second= “He is an honest person”;console.log(second.charAt(6));//output : a

2.concat(): In this method, Any string can add each other by using this method. For example:

const first= “He is an honest person.”;
const second= “I know him very well”;
console.log(first.concat(‘’ ,second ));//output: He is an honest person. I know him very well

3.include(): In this method, In this string, the word has or has not found out. By boolean style means true or false give the output result. For example:

const first= “He is an honest person.”;
console.log(first.includes(‘He’));
//output: trueconst second= “He is an honest person.”;console.log(second.includes(‘She’));//output: false.

4. startsWith(): In this method, found out the starting word of the string if match then results will be true or does match the result will be false. For example:

const first= “He is an honest person.”;
console.log(first.includes(‘He’));
//output: trueconst second= “He is an honest person.”;console.log(second.includes(‘She’));//output: false.

5.endsWith(): In this method, found out the ending word of the string if match then results will be true or does match the result will be false. For example:

const first= “He is an honest person.”;console.log(first.endsWith(‘person.’));//output: trueconst second= “He is an honest person.”;console.log(second.endsWith(‘he’));//output: false.

6.indexof(): In this method, you can found out the position of the word in the string start with 0 which is the first word of the string. If the position have then the output will be in position number else the output will be -1. For example:

const first= “He is an honest person.”;
console.log(first.indexOf(‘He’));
//output: 0const second= “He is an honest person.”;console.log(second.indexOf(‘She’));//output: -1

7.lastindexof(): In this method, you can found out the position of the word in the string start with 0 which is the end word of the string. If the position have then the output will be in position number else the output will be -1. For example:

const first= “He is an honest person.”;
console.log(first.indexOf(‘person’));
//output: 16const second= “He is an honest person.”;console.log(second.indexOf(‘She’));//output: -1

8.replace(): In this method, you can change any word by the string. For example:

const first= “He is an honest person.”;
console.log(first.replace(‘He’, ‘Rahim’));
//output: Rahim is an honest person.

9.slice(): In this method, you can select any word from a string to start your sentence other word will vanish. For example:

const first= “He is an honest person.”;
console.log(first.slice(9));
//output:honest person.

10.split(): In this method, you can separate and make new space in the string for words. For example:

const first= “He is an honest person.”;
const word = first.split(‘ ‘);
console.log(word);//output : [ ‘He’, ‘is’, ‘an’, ‘honest’, ‘person.’ ]

11.substr(): In this method, you can take any word of the string by position to start your sentence if you choose any word position then start position only stand by other will be gone. For example:

const first= “He is an honest person.”;
console.log(first.substr(‘9’));
//output: honest person.

12.toLowerCase(): In this method, you can make all words in small letters. For example:

const first= “He is an Honest Person.”;
console.log(first.toLowerCase());
//output: he is an honest person.

13.toUpperCase(): In this method, you can make all words in upper letters. For example:

const first= “he is an honest person.”;
console.log(first.toUpperCase());
//output:HE IS AN HONEST PERSON.

14.trim(): In this method, you can remove all extra whitespace in the string. For example:

const first= “   He is an honest person  “;
console.log(first.trim());
//output: "He is an honest person".

15.trimStart(): In this method, you can remove all extra whitespace from starting side of the string. For example:

const first= “    He is an honest person   “;
console.log(first.trimStart());
//output: "He is an honest person ".

16.trimEnd(): In this method, you can remove all extra whitespace from the ending side of the string. For example:

const first= “   He is an honest person   “;
console.log(first.trimEnd());
//output: " He is an honest person".

Bonus: SSL
SSL means Secure Sockets Layer. All the website URL start with
HTTP:// or HTTPS:/.This two have just a one-word difference which is “s”.These “s” mean SSL. That means your search website more secure to visit. Always try to see the first URL starting is HTTPS or not cause HTTP is not secure. If form fillup or pay the bill then you have to share some personal information so that if the website does not secure then the hacker can easily get your information which is risky for you. Hopefully, now you always see the first URL which HTTPS:// or not.

--

--