All js strings method - less text , more snippet
Tags: javascript, codenewbie, webdev, string
Published: 2021-07-19 21:35:12

1. String.length :
===========
  * Returns the length of the string.
![length](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nf4n1fkkodz2wqkhxcyd.png)

2. indexOf( ) :
==========
  * Returns the starting index no of searching character or word.
  * It searches forward.
  * It takes 2 argument, 2nd argument is for search starting index number and 2nd argument is not compulsory.
  * If searching string does not found then it will return -1
![indexof](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mcvbi8e34vz2rubgm3ct.png)

3. lastIndexOf( ) :
==========
  * same as indexOf() just difference it starts searching from last or backward
![last index of](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3uryfiw3cqnbcpjb71io.png)

4. search( ) :
========
  * same as previous two just difference is search() and does not take 2nd argument and always search forward.
![search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8ka9nruoo8c3ytzk0w8.png)

5. includes( ) :
========
  * Returns true or false as the given string is present or not on the main string.
![includes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q6yo9dfrokkueae52p4g.png)

6. startsWith( ) :
==========
  * Returns true or false as the main string starts with the given text or not.
![startsWith](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hc1fhgckkwpf5fsmw2n5.png)

7. endsWith( ) :
==========
  * Returns true or false as the main string ends with the given text or not.
![endswith](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vx0gkbncumr0rrlhp4bu.png)

8. replace( ) :
===========
  * Takes two argument - (present string, replaced string).
  * It replaces only the first matched.
![replace](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/08a5ztb0wk1ef5s3xv36.png)

9. replaceAll( ) :
=========
  * will replace all matching string on main string.
  * VS code does not give suggestion for replaceAll() but you just type , it will work.
![replaceAll](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1xgn1wrqe1ogh166gni.png)

10. toUpperCase( ) :
==========
  * Converts whole string to uppercase.
![uppercase](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ucmbphtizbhphbs0q14.png)

11. toLowerCase( ) :
=========
  * Converts whole string to lowercase.
![lowercase](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bv6shx0ofnoap3ton5z0.png)

12. trim( ) :
==========
  * Removes whitespaces from start and end of the string.
![trim](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4j88x5msfci35jgh40b.png)

13. concat( ) :
=========
  * Join two different strings.
![concat](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m4xqep3seflu77l9cb4l.png)

14. repeat( ) :
========
  * Repeats a string from 1 to infinity times. Just need to mention repeat number inside ( )
![repeat](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2ekydv2e5a6zmpf3z3l.png)

15. charAt( ) :
=========
  * Accessing string characters with index num.
![charAt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lojj1l6mq3vf9z8axxar.png)

16. charCodeAt( ) :
=========
  * Accessing string character's UTF-16 code with character's index number.
![charcodeat](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggqn2ezmagc7gtz0vrrx.png)

17. slice( ) :
===========
  * Extracting string from a string.
  * takes two argument - (starting index, ending index) . ending index is not compulsory.
  * ending index= -1 means till end.
![slice](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jhkilrvsoeqxckzs04gk.png)

18. substring( ) :
===========
  * substring() is similar to slice() the difference is substring does not except negative indexes.
  * If we give negative value then the character are counted from the 0th position.
![substring](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0buxn2zemeek3qxp6cd.png)

19. substr( ) :
============
  * 2 argument- (starting index, length of new string). 2nd argument can't be negative.
![substr](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0buxn2zemeek3qxp6cd.png)

20. match( ) :
=============
  * The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object.
![match](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cfkptdkmfatbg4hxmnb6.png)

21. padStart( ) :
===========
  * Add white spaces at the start of the string. Inside ( ) you need to give your total string length with starting whitespaces.
  * whitespaces = length - string characters length
![padstart](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7naal8krb30bj363ryu.png)

22. padEnd( ) :
=========
  * same as padStart( ) just here whitespaces will add at last.
  * To recognize spaces , bellow in pic in comment at last added '|'
![padend](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7kwifst6sb19mru2oqtp.png)

23. split( ) :
=============
  * Break string and convert it in array.
![split](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nxtgx8l0sm0n4w6nkfe2.png)

24. codePointAt( ) :
========
  * Return unicode value of given character.
![codepointat](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/691ko1v3qsth21qzgoj2.png)

25. fromCharCode( ) :
=========
  * Return character from unicode value.
  * in bellow pic comment ans is 
// TSb
![fromcharcode](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h47agwgpb9zgzbjulbk8.png)

26. localeCompare( ) :
=======
  * Two string comparison. The reference or base string always written at first then .localeCompare(string2)
  * Returns negative number (-1) if the reference string is sorted before string2.
  * Returns 0 if two strings are equivalent.
  * Returns positive number (1) if the reference string is sorted after string2.
![localeCompare](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqeyjk2wnb2s1fn64wia.png)

---------------------------------------------------
so here we are ! Feel free bookmark this blog for **Quick revise** on any time.
I tried best to mention all method even some similar to each other. But if i missed any method please tell me comment.

-------------------------------------------
###And connect with me on [twitter](https://twitter.com/Sahilsaif2002) for other JavaScript and CSS stuff.