Java Script for salesforce developers Part 3

 



JavaScript strings are used for storing characters. it is written under quotes. strings written under single or double quotes works same. there is no difference between the two.



String Methods :

JavaScript provides several string methods to manipulate the string. here are some examples of these methods.



1. Length:

length is used to check the length of specific string.



2. CharAt():

CharAt method is used to retrieve the character at specific index



3. Substring():

This method returns a substring based on start and end indices.



4.touppercase() and tolowercase():

touppercase() method is used to convert the string into uppercase 

tolowercase() method is used to convert string into lowercase.


5.indexof() and lastindexof():

indexof() method return the index number of character if  specific alphabet occur twice in string then it will give index for first occurrence.

lastindexof() method return the index number of last occurrence of character. 


6.Replace():

This method is used to replace the particular word with  another word in string . 


7.Concatenation 

 Developer can concatenate two strings using  "+" operator


8. Slice():
 This method return portion of string between specified indices . 




9. split():
 Splits a string into an array of substrings based on the specified separator.



10. startswith(Prefix) and endswith(suffix):
This method Checks if a string starts or ends with the specified prefix or suffix.



These are some common string method that developers use frequently. but java script provide several other string methods that developer can use as per requirement.

Some of methods are :
  • includes()
  • repeat()
  • trim()
  • charcodeAt()
  • match()
This is all about string method in java script in next blog post we will discuss about array , functions  . stay tuned.








Comments