We are going to share Top javsscript string manipulation method by which you can speed up your development.
- String Property Access
- Converting a String to an Array(
- String Length
- Finding a String in a String(
Lets take a look in each one of them in detailed way.
By this method string will be converted to uppar case like "abc" will be "ABC"
A string is converted to lower case with
toLowerCase() like "AbCD" -> "abcd"
concat method is used to join two string
trim() method is used to remove whitespace from both side of string.Sometime its better to remove whitespace because cannot be make sure frontuser will give input without space.
charAt() method is used to return the character at a specified index (position) in a string.
6) String Property Access
If you want to access string property with respect to array index like.
If you wan to convert string to array you can use method to make it work.
length property of javsacript will return the length of given string.This property is usefull is you want to check if string is not empty.
9)Finding a String inside a String(
lastIndexOf() methods.But the major difference between two method is The
indexOf() method returns the index of (the position of) the
first occurrence of a specified text in a string and
lastIndexOf() method returns the index of the last occurrence of a specified text in a string
Both method will return -1 is checked string is not found.
search() is also similar to
indexOf() method but the major difference between two method is
search()method cannot take a second start position argument.
indexOf()method cannot take regular expressions.
11)Extracting String Parts
In substr If the first parameter is negative, the position counts from the end of the string.
replace() method replace given string with new string as
As above example you can see
replace() method does not change the original string instead of that it return the update string.Most important
replace() method is case sensitive so you need to take care while using it.