Do you get confused so often with these 10 javascript methods? Let’s explore a bit more….

1.String indexOf()

If you want to find a specific position of a value, then you can use the indexOf() method. But you should remember that it’s a case-sensitive method. Here is an example-

indexOf() method

2. Array slice()

Suppose, you have an array with a couple of elements. Now you want to get some specific elements from the array. In this case, you can use the slice method. It will give you a new array. But the previous array won’t change.


3. String split()

This method converts a string into a substring and gives you a new array. In other words, it divided the parent string into child string and each child string turns into a specific element in the new array.


4. Math ceil()

You need to use some simple mathematical terms in web development so often. Sometimes you get fraction results during calculation. It looks so odd. How can you get rid of it? Well, you can use the ceil() method to round the digit upward to the nearest integer.


5. Math floor()

It is almost the same as the previous example. In the previous example, the digit turned upwards to its nearest integer. In this method, the digit goes downwards to its nearest integer. So simple, isn’t it?


6. Math random()

If you want to get random results in mathematical terms, you can use this method. Absolutely you will get a random number.No matter it is an integer or fraction.


7. Math round()

If you think that you are not satisfied with your fraction results which you get from your mathematical terms, you can use this method. Yes, it’s the round method and it rounds a number to its nearest integer. I hope you get it.


8. Array push()

It is one of the most common methods, used in javascript. Suppose, you want to add a new element into an array. In this case, you can use the push method. It will add new elements instantly to your desired array.


9. Array pop()

Can you guess, what’s the use of this method by getting concepts from the previous one? Yes, you get it. It’s the method that is used to remove the last element from an array. So easy, right!!!


10. Array sort()

If you want to re-arrange your array’s elements alphabetically. you should use the sort method. As you can see in the image below, all the element is sorted alphabetically by using this method.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store