> ## Documentation Index
> Fetch the complete documentation index at: https://blog.sumathi.dev/llms.txt
> Use this file to discover all available pages before exploring further.

#  Map Filter Reduce

* higher order methods

## Map

* creates a new array by performing some action on each element
  * forEach does not do this , but you can just iterate though it
  * let a = num.forEach is not possible
  * ```js theme={null}
      // Map Filter Reduce - higher order methos
      let arr = [45 , 23 , 44]
      console.log(arr)
      // Array Map method
      // .map creates new array .forEach modifies the same array
      let newarr = arr.map((value,index,array)=> {
          console.log(value,index,array) // index and array are optional args
          return value*value
      })
      console.log(newarr)
    ```

## Filter

* * Does some filtering based on a function and makes new array
  * ```js theme={null}
      // Filter
      let arr2 = [0,3,5,45,56,78]
      let newarr2 = arr2.filter((value)=> {
          return value<10
      })
      console.log(newarr2)
    ```

## Reduce

* Traverses through the array and returns smaller dimesion value
* ```js theme={null}
   // Reduce method
   let arr3  = [0,3,5,4,6,7]
   let newarr3 = arr3.reduce((value1,value2)=> {
       return value1 + value2
   // it takes first two values and runs the function and takes the output and runs on 3 element and continues
   })
   console.log(newarr3)
   const sum = (a,b) => {
       return a + b
   }
   console.log(arr3.reduce(sum)) // same as giving function inside
  ```
