Inbuilt Methods In JavaScript

September 15, 2021

What is methods in JavaScript ?

Methods in JavaScript is like a function which we can perform on objects or on array or on string .It is a property of an object which contains function defination.

Types of method in JavaScript:

There are two ways you can have methods of JavaScript

  1. By defining it yourself
  2. By using Inbuilt Methods in JavaScript

Here, we will focus on different Inbuilt JavaScript methods.So let's start,

We will see here useful string methods and array methods.

  1. Slice()

  2. This is a string method which copy some part of string without modifiying the original string.

    Example :- On string

    var str = "JavaScrispant is cool" ;

    • str.slice(); // 'JavaScript is cool'
    • str.slice(4); // 'cript is cool'
    • str.slice(1 ,11); // 'avascript '

    On Array

    const flowers = ["Rose" , "Sunflower" , "daffodils", "Lily"];

    • flowers.slice(); // ['Rose', 'Sunflower', 'daffodils', 'Lily']
    • flowers.slice(1); // ['Sunflower', 'daffodils', 'Lily']
    • flowers.slice(1 ,3); //  ['Sunflower', 'daffodils']
  3. toUpperCase()

  4. As the name says itself this method converts the String to uppercase but without affecting the original string.

    Example :- var str = "kajal kumari"

    • str.toUpperCase() // "KAJAL KUMARI"
  5. toLowerCase()

  6. As the name says itself this method converts the String to Lowercase but without affecting the original string.

    Example :- var str = "JAVASCRIPT"

    • str.toLowerCase() // "javascript"
  7. repalceAll()

  8. This method return a new string based on provided replacement after replacing it in string.

    Example :- 1. var str = "15-09-2021"

    2.var str2 = "write the Blog"

    • str.replaceAll('-' , '') // "15092021"
    • str2.replaceAll('write' , 'read') //    "read the Blog"
  9. charAT()

  10. This method return specified character from a string of specified index.

    Example :- var str = "Hello World!"

    • str.charAt(3) //    "l"
    • str.charAt(7) //    "o"
  11. split()

  12. This method split the string on the basis of argument you pass in it.

    Example :- var str = "Welcome to programming world!"

    • str.split('') //    ['W', 'e', 'l', 'c', 'o', 'm', 'e', ' ', 't', 'o', ' ', 'p', 'r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g', ' ', 'w', 'o', 'r', 'l', 'd', '!']
    • str.split(" ") //    ['Welcome', 'to', 'programming', 'world!']
    • str.split('o')//     ['Welc', 'me t', ' pr', 'gramming w', 'rld!']
  13. join()

  14. This method return an array of string joining all the breakpoints

    Example :- var arr = ["Welcome" ,"to","programming" "world!"]

    • str.join('') //    'Welcometoprogrammingworld!'
    • str.split(" ") //    'Welcome to programming world!'
    • str.split('o') //     'Welcomeotooprogrammingoworld!'
  15. reverse()

  16. This method reverse the order of the array and then return it as array of strings.

    Example:- var arr = ['W', 'e', 'l', 'c', 'o', 'm', 'e']

    • str.split(" ") //     ['e', 'm', 'o', 'c', 'l', 'e', 'W']

Hope you enjoyed the blog. For now bye bye 🚶‍♀️