Javascript methods

Mostafa Mahmood
4 min readNov 2, 2020

Javascript is the most popular language in the world. Without it, no one can imagine websites nowadays. While coding in javascript we have some built-in methods. We will discuss the 10 methods today.

1. charAt()

We can excess an individual character in a string by using charAt() methods. Let me give u an example below :

Using charAt() method

Here I excessed g in string “tiger” and g is situated on index number 2. After ES5 we can excess g by writhing animal[2] in above.

2. toLowerCase()

We can make any string to lowercase by using toLowerCase() method. Let me give u an example below :

Using to LowerCase() method

Here by using toLowerCase() method, I make a whole sentence in lower case. You can also use toUpperCase() method to make string uppercase.

3. includes()

We can check any string available in any string sentence. Let me give u an example below :

Using includes() to check

Here I checked “popular” belongs in the language variable and that returned true. Includes() return boolean value.

4. trim()

We can remove whitespaces from both sides of the strings. Let me give u an example below :

Using trim() method

Here I used trim() method to remove whitespaces of both of the strings. So return came Happy coding!

5. Math.max()

We can get the maximum number from a collection of numbers with Math.max(). Let me give u an example below :

Using Math.mac() method

Here I used Math.max() to get the largest number from the age collection and that was 42. You can also use Math.min() to get the smallest number.

6. parseInt()

We can change the string value to an integer value by using parseInt() method. Let me give u an example below :

Using parseInt() method

Here I used parseInt() to change string value to number value and that was 34. You can also use parseFloat() to get a floating number while the program will be returning one.

7. push()

We can insert a new element at the end of the array. Let me give u an example below :

Using push() method in array

Here I use push() method to insert “Smart & Final” into the store array. You can use pop() to remove an element from the last.

8. shift()

We can remove the first element of the array by using shift() method. Let me give u an example below :

Using shift() method

Here I used shift() to remove “Jons” means the first element from the store array. You can also use unShift to add an element.

9. find()

We can find just a single element from an array. Let me give u an example below :

Using find() method

Here I used find() method get less than 30. One thing with find() it will always return the first element of the array whatever match with the condition. You can also use filter() method to get all the elements whatever the condition matches.

10. map()

We can use map() method to get a new array and the result will be depending on the calling function that has been called in the map() method for every element. Let me give u an example below :

Using map() method

Here I used map to get a new array that replied a result and that was depending on the calling function. one quick thing map() doesn’t change the original array.

There are many methods available to help the developer’s life easier. I just mentioned 10 of them. So as a javascript developer we should know those methods to make our code faster and efficient.

--

--