JavaScript string methods. [part — 1]

Sivaprasad EV
2 min readJan 17, 2022

--

We all know that JavaScript ( JS ) playing an essential role in web development. So that, it is vital to understand it’s fundamental concepts and inbuilt methods.

I will going to explain each an every inbuilt JS methods along with examples. To make it short, I only describe 2 methods in my each article.

In this article I will start with string methods. So, Let’s dive into it.

1 ) trim ( ) method

  • trim ( ) method let you remove extra white spaces from both ends of string and return a new string.
  • it is a best method you should consider when you want to eliminate space from either beginning or end of string.

consider the following example and try it yourself.

Example for trim JS method
  • if you run the above code snippet you will white space would be removed from string ‘ hello ’ and you will have new non-space string ‘hello’.
  • It can be identify if you compare the length of each strings.

If you need deep knowledge of any JS methods please visit https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

2 ) charAt ( ) method

  • This method takes an index and returns a character from the string at given index.

Consider the following example

Javascript charAt string method example.
  • The above example will return the character ‘h’. Because, I specified index of 0 (zero) to charAt ( ) method. So, it gave me the character at index position zero.

Please always try out all the given examples by yourself. Having a theory knowledge does not stick in your mind forever. So, please have try out all the examples giving on any articles you have been going through.

I do daily posts on Instagram about JavaScript methods and tips. If you would interested to join with me please check out the below link.

https://www.instagram.com/thinklikeatechy/

Thank you : )

--

--