10 Javascript methods everyone must know

Javascript is a dynamic language, its syntaxes are similar to others programming languages. like java and c.

Javascript is called a functional programming language. They have objects, functions, and variables.

Similar to other programming languages they have string, loop, and function. Javascript also called an object-oriented programming language.

Variable

parseInt() and parseFloat():

parseInt method parses a string value then returns an integer value. If someone wants to parse any string he must put a radix. Radix is nothing but the base of a number.

Rember number.parseInt() and parseInt() are similar.

Similar to parseInt, parseFloat parses a string but return a float number. It does not need any radix.

Ceil(), floor(), round()

Math.ceil() is a function which returns next largest round number. Suppose if we write Math.ceil(3.2), it will return 4 which is the next largest round number.

Math.floor() also a function and it return the smallest round number. Suppose if we write Math.floor(3.2) it will return the smallest round number which is 3.

Math.round() always return an integer number which is the nearest round number of it. If the fractional part is equal or larger then. 5 it will return the next rounded integer number. And smallest. 5 it will return the smallest round number.

If we write Math.round(3.7) it will return 4 and if we write Math.round(3.4) it will return 3.

String

StratsWith() and endsWith()

stratsWith return boolian value, true or false. This method use in string and array. If we put any value to this method, this method will return boolean value true or false.

Suppose a=’karim’

console.log(startsWith(‘ka’))

Output will be true

console.log(startsWith(‘na’))

Output will be false

endsWith() is similar to the start with startsWith() method. This method also return true or false

Suppose a=’karim’

console.log(endsWith(‘im’))

Output will be true

console.log(endsWith(‘na’))

Output will be false

splice() and replace()

splice() method replacing array element by adding new element. If we write const a=’selfie’

a.splice(1,0,p)

the output will be ‘saelfie’

Here p element enters to the index 1 of this string.

The replace() method replace a string if the string is matched. Suppopse

a=’I am a quick learner’

a.replace(‘quick’,fast’)

Output will be I am a fast learner

The pattern will be regex or,string

indexOf() and concate()

indexOf() method returns the original index of the specific string and if the index is not found it will return -1.

const a=’Asus’

a.indexOf(‘U’)

Output will be 2 (index)

concate() method joined two string and return a new string.

Suppose a=’Bangladesh’

b=’India’

a.concate(“”,b)

Output will be “Bangladesh India”

toUpperCase() and toLowerCase()

toUpperCase() method returns an upper case string from any string.

const a=’I am a good boy’

a.toUpperCase()

Output will be “I AM A GOOD BOY”

toLowerCase() method also return a new string with lowercase value.

const a=’I am a Good boy’

a.toLowerCase()

Output will be “i am a good boy”

Array

push() and pop()

In push() method insert an item to the array and insert the item as the last element.

After finishing the push() method the array length will be an increase

const p=[‘a’,’b’,’c’]

p.push(‘d’)

Output will be [‘a’,’b’,’c’,’d’]

pop() method removes an array element from the last and after completing this the array length will be decreased.

const p=[‘a’,’b’,’c’]

p.pop()

Output will be [‘a’,’b’]

map()

map() is a popular array method that returns a new array with a specific condition. For this, a const value must need for keeping the new array.

const array=[2,3,4,5]

const newArray = array.map(ar=>ar*5)

Output will be [10,15,20,25]

find()

Find is an array method that returns the first matched element. It returns the value if the argument conditionally satisfied and always return the first matched element.

const array=[4,5,6,8]

const newArray= array.find(arr=>arr>5]

Output will be 6

filter()

filter() is a popular array method that return a new array if the condition is matched. In the filter method, the function returns all the matched elements and creates a new array.

Example

const array = [2,3,4,5]

const newArray = array.filter(arr=>arr%2==0)

Output will be [2,4]

I am a Mern Stack web developer.