A string is a collection of characters. Where the first index starts from 0.
A method that is used in string operation. It is used to access an individual character in the string. Such as
const name = “asif ur rahman”;console.log(name.charAt(1)); //returns s.
This method is used to contact several strings. Such as
const firstName = “asif ur”const lastName = “rahman”const fullName = firstName.concat(lastName)console.log(fullName)// returns asif ur rahman.
This is a case-sensitive method. It works with true and false. a specific string is passed through this includes method. If the string is matched with a given string then it will return true. If no match occurs then it will pass false.
const str = “I am Md. Asif Ur Rahman”;const result1 = str.includes(“Asif”);const result2 = str.includes(“World”);console.log(result1) // return trueconsole.log(result2) // return false
It works like boolean algebra which means true or false. It checks if a given string ends with the string which is passed through endsWith().
const str = “I am Md. Asif Ur Rahman”;console.log(str.endsWith(‘Rahman’)); //trueconsole.log(str.endsWith(‘Ur’)); //false
It is a case-sensitive method that identifies the first occurrence of a string.
var str = “I am Md. Asif Ur Rahman”;console.log(str.indexOf(“Ur”)) // return 14
It identifies the last occurrence of a specified string.
var str = “I am Md. Asif Ur Rahman. I am a programmer.”;console.log(str.lastIndexOf(“am”)); // 36
It identifies a specific string and replaces it with another string.
const str = “I am Md. Asif Ur Rahman. I am a programmer.”;console.log(str.replace(“programmer”, “codder”)); //I am Md. Asif Ur Rahman. I am a codder.
Slice means to extract some character in a given string. Where a and b identify the index. a is the first index and b is the last index. The slice method will cut between these two index.
const name = “Asif Ur Rahman”console.log(name.slice(8,14)) // Rahman
This split method split the total string as a collection of arrays. It does not change the original string. It is case-sensitive also.
const name = “Asif Ur Rahman”console.log(name.split(“ “)) // ["Asif","Ur","Rahman"]
It works with boolean. If one specified string starts with a given string, it will return true else it will return false.
const name = “Md Asif Ur Rahman”console.log(name.startsWith(“Md”)) // true
N.B: Upcoming article with substr, toLowercase, toUppercase, trim, trimStart, trimEnd.