Javascript Array Methods One Must Know

|
| By Webner
  1. filter

    The filter is an array function in vanilla.js which returns a new array by filtering the filter item provided to the filter function.

    Here is ES6 syntax for this function:
    Array

  2. Reduce

    This function basically executes a given function provided to it. It is used to add/multiply/divide/subtract and also provide an imploded string of given values inside the array.

    Here is ES6 syntax for this function:
    javascript-code1
    javascript-code2

  3. forEach:

    This function is used to iterate through each element of the array similar to for loop. Basically used to write or list all items of it.
    Here is ES6 syntax for this function:
    javascript-code3

  4. Every and some

    These two functions are quite similar to each other but have one major difference: every function performs a given test and every element needs to pass that test whereas, in some functions, at least one element needs to pass the test. These functions return boolean value as a response.

    Here is ES6 syntax for this function:
    array javascript-code4

  5. Includes

    The purpose of this function is used to find a value that exists or not exists in an array. It returns a boolean value.

    Here is ES6 syntax for this function:
    array javascript-code5

  6. Map

    Last but not least, the map function returns a new array by performing a particular function on each and every element of it.
    Here is ES6 syntax for this function:
    array javascript-code6

—– 😉 HAPPY CODING 😉 —–

Leave a Reply

Your email address will not be published. Required fields are marked *