JavaScript array function

Total Post:113

Points:791
 194  View(s)
Ratings:
Rate this:

How to use of JavaScript Array Functions ?

  1. Post:140

    Points:984
    Re: JavaScript array function

     use JavaScript Array Functions :

    1. prototype.reduce():  A callback function 

    syntax : 

    arr.reduce(callback[, initialValue])
    

    ex. 

    function reduceFun1(previousValue, currentValue, index, array){ 
        return previousValue + currentValue;
    }
    var result = [1,2,3,4,5].reduce(reduceFun1);
    console.log(result);  

    2. prototype.concat(): 

      syntax : 

    NewArray = Array1.concat(value1[, value2[, ...[, valueN]]])
    

    ex.

    var arr1 = [1,2,3,4];
    
    var arr2 = [5,6,7,8];
    var arr3 = arr1.concat(arr2);
    console.log(arr3);


    3.prototype.sort():

    syntax:

    arr.sort([compareFunction])
    

    ex.

    var arr = [3, 1, 5, 4, 2].sort(); 
    console.log(arr);


    prototype.reverse():

    syntax:

    array.reverse()
    

    ex. 

    var arr = [1,2,3,4,5,6,7,8,9,10];
    
    arr.reverse();
    console.log(arr);

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!