JavaScript methods you should know about.

 
                    Hello folks, hope you all doing well . In this particular blog i am sharing some of tradition but evergreen javaScript methods that every one should know about.

Methods

forEach : This method allows you to iterate through all the elements present inside the array, pretty similar to forEach of other programming languages.

example: 

        
        array.forEach(function(currentValueindex){    
          /**
          * stuff to perform with each record
          */
        });

map : This method returns a new array by calling the provide method once for each and every element present inside array in the order in which they stored into array, it does execute the provide method for empty value of array.
            
example :


        array.map(function(element){
          /**
           * stuff to perform to each element of array
           */
        });


filter : This method returns an array that passes the condition matches into the method provided, it does execute the provide method for empty value of array.

example :


        array.filter(function age) {
          /**
          * filter condition and return data logic
           */
        });    



reduce : This method takes each element of array and the last calculated value started from left most index of array and returns a final single value based on the action performed in method provided.

example :


        array.reduce(function(finalValcurrentVal) {
          /**
          * calculation on final and current value of array
           */
        });


reduceRight : This method is similar to reduce, the key difference is that it starts evaluation from right most index of array.

example :


        array.reduceRight(function(finalValcurrentVal) {
          /**
          * calculation on final and current value of array
           */
        });



join : As the name suggest, this method joins each entries into array as a string based on the separator provided. The default separator is  comma.

example :

        array.join('-');

splice : This method add/remove elements to/from an array based on param provided.

parameter description : 
array.splice(index, times, element1, ....., elementN)

index : Required int param indicating the position where elements can be added/removed. We can use negative value to mention index from last index.
times : Optional param indicating the number of elements to be removed.
element1,...,elementN : Optional param indicating the items to be added into array.

includes : This method takes elment as an param and tests its presence into array and returns boolean value accordingly. Note that element comparison is case sensitive here.

example : 


        array.includes(elementToTest);

Comments

Popular posts from this blog

Jasper report integration in Spring boot/Spring MVC.

FireBase Crud operation in Spring Boot

Hybris Overview and b2c installation initialization