DEV Community

Rahul Ghosh
Rahul Ghosh

Posted on

Some Regular JavaScript Methods for JS Developers...

Use of extracting string method

1 slice(start, end) Method
1Slice

The Slice method takes two parameters, the first one where the extract starts position, and the last one extract end position. The Slice method is used when some specific string is extracted in a string. If a parameter is negative, the position is counted from the end of the string. If you do not use the second parameter, the result will slice out the rest of the string. Slice can accept negative indexes.

2.substring(start, end) Method
3subStr

substring() is the same to slice() Method. The difference between substring() cannot accept negative indexes. This method also has two parameters first one is extracted start positions and the last one is extracted end position.

3 substr(start, length) Method
3subStr

substr() is also the same as slice() But the difference is that the second parameter specifies the length of the extracted part. If you omit the last parameter, the result will slice out the rest of the string.

Use of number method

4 parseInt() Method
4parseInt

The parseInt() method parses a string. This method returns a whole number. These method spaces are allowed. Only the first number is returned.

5 parseFloat() Method
5parseFloat

The parseFloat() method converts strings to numbers. If the number cannot be converted, NaN (Not a Number) is returned. This method is used in regular needs.

Use of Math method

6 Math.abs() Method
6abs

The Math.abs() returns the absolute (positive) value of x . When you need a positive value from a negative number it is a helpful method for a developer.

7 Math.pow() Method
7pow

Math.pow(x, y) returns the value of x to the power of y. This is a built-in method in Javascript Math.

Use of array method

8 Pop() method
8pop

Array in js plays an important role in development. Pop() is a built-in method of javascript. The pop() method removes the last element from an array. This is a method of the array.

9 Push() method
9push

Sometimes we need to add some items in an array, so what we do that time! The push() method adds a new element at the end to an array. This method returns the new array length.

10 shift() method
10shift

The shift() method removes the first array element and "shifts" all other elements to a lower index. This array method is similar to pop() but different from removing item position.

Top comments (0)