Javascript Methods that will boost your skills

 Here are the Javascript Methods that will boost your skills.



1. Spread Operator


    const favoriteFood = ['🌭''🍕''🍟'];
    console.log(...favoriteFood,'🥞');
    //🌭 🍕 🍟 🥞


The Spread Operator expands an array into its elements. It also is used for object literals.


2. FOR...OF ITERATOR


    const persons = ['👩''👨''👧''🧒''👶'];

    for (const item of persons) {
        console.log(item);
    }

    //👩
    //👨
    //👧
    //🧒
    //👶
    


The for...of statement loops through the collection, and provides you the ability to modify specific items. It replaces the conventional way of doing a for-loop

3. Includes Method


    const persons = ['👩''👨''👧''🧒''👶'];
    const findPerson = persons.includes('👩');
    console.log(findPerson);
    //true


The includes() method is used to check if a specific string exists in a collection, and returns true or false. Keep in mind that it is case sensitive: if the item inside the collection is NAME, and you search for a NAME, it will return false.



4. Includes Method


    const age = [202122];
    age.some(person => person => 22)

    //true


The some() method checks if some elements exist in an array and return true or false. This is somewhat similar to the concept of the includes() method, except the arguments in a function and a string





5. Every Method



    const age = [202122];
    age.every(person => person => 22)

    //true


The every() method loops through the array, checks every item, and returns true or false. Some concepts as some(). Except for every item must satisfy the conditional statement, otherwise, it will return false.


6. Filter Method


    const prices = [203015554010];
    prices.filter(price => price >= 30)

    //[30,55,40]


 The filter() method creates a new array with an element that passes the test.


7. Map Method


    const priceList = [100850250055000];
    priceList.map(price => price * 50);
    
    //[5000, 42500, 125000, 2750000]
    

The map() method is similar to the filter() method in terms of returning a new array. However, the only difference is that it is used to modify items.


7. Reduce Method



    const array = [100200300400500013000]
    array.reduce((firstlast=> first + last)

    //19000



The reduce() method can be used to transform an array into something else, which could be an integer, an object, a chain of promises (sequential execution of promises), etc. For practical reasons, a simple use case would be to sum a list of integers. In short, it reduces the whole array into one value.

Thanks for reading.... 👏👏👏


Reactions

Post a Comment

1 Comments

  1. Love the simplicity of the articles, but please do not do the emojis anymore. It's hurting my brain.

    ReplyDelete

If you have any question please ask?