JavaScript String Methods

Md Solayman
2 min readMay 4, 2021

--

  1. charAt(): This method is used to find out any character of a string at a individual position like if I use ‘rahim’.charAt(1), this will return “r” as value
  2. concat(): This method does nothing but addition of string. Example : ‘rahin’.concat(“,” , ”karim”) and the output will be, “rahim, karim”
  3. endsWith(): This method returns boolean value which that determines whether the string end with given character or not. Example: let str=”my name is rahim”. str.endsWith(“rahim”) will give the output true.
  4. indexof(): This method returns the value of index of a specific character of a string. If it has multiple same character this will return the index of first occurrence character only. Example : let name= “karim dadu valo manus”; name.indexof(“valo’). This will return 6.
  5. toLowerCase(): This method actually transform all the characters of a string to uppercase. Example : “Karim”. toLowerCase(). The output will be “ karim”
  6. toUpperCase(): This method is just opposite of toLowercase() method. In this case it will transform all the characters to uppercase. Example : “solayman”.toUpperCase(). The output will be “SOLAYMWN”
  7. split(): This method is used to split a string into a array of substring. Inside the parenthesis separator is passed. let str=”What is your name?”; str.split(“ ”) will return [ “What”, “is”, “your”, “name?”]
  8. substr(): This method extract a string from another string where we have to specify the index of that character from where the sub string will start and number of character you want from the initialization . It doesn’t change the main string. Syntax will be like, string.substr(start index, length). Example:let string= “karim uddin valo sele”; string.substr(0,3) output will be “kar”.
  9. slice(): Slice is another string method that returns a extracted string determined by the input of this method. It takes two values as input. First the starting character index from where you want to start your extraction and second, the ending index of of the character +1 where you want to finish. Example : let str=”Rahim is a brilliant boy”; str.slice(0,3) will return “Rah”.

Number method of JavaScript:

  1. isNaN(): This is a method that check an element whether it is a number or not and returns a boolean value. If the element is not a number, it returns true else it returns false

Example : (“karim”).isNaN() will return true. Again (123).isNaN will return false.

--

--

Md Solayman

An enthusiastic learner , currently focused on Web Development using HTML, CSS, Bootstrap, JavaScript , React, Node, Express Js, Mogodb.