Tech Junkie Blog - Real World Tutorials, Happy Coding!: JavaScript Array Methods : filter() Method

Wednesday, December 15, 2021

JavaScript Array Methods : filter() Method

The filter() method returns the elements of the array that satisfies the function that is passed into the method.  If the function returns true the element is added to the filtered array, else it is ignored.

Let's say we only want to buy oil when the prices drops below $72, so we will only return an array element where the prices below $72


    <script>
        var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99];

        var lowPrices = oilPrices.filter(function (value) { return value < 72 });

        console.log(lowPrices);
    </script>














1 comment:


  1. WHY SHOULD YOU REMODEL YOUR LAUNDRY ROOM?
    Your laundry room, while possibly dainty and a bit unorganized ends up being one of the most vital rooms in your home. This is where most of the family shares a limited number of common utilities and quality care for your clothes goes a long way. Although when it’s time to remodel, it’s likely one of the last rooms of the home that is thought of, and sometimes even forgotten. Your washer and dryer may just be in a corner of the basement, the dedicated space in the garage or taking up a closet. Don’t ever neglect or overlook the fact that you may need more space or new equipment. No matter where your laundry room is located within your home, we have the experience and craftsmanship to design and build an amazing, new laundry room. If you are looking for a complete laundry room remodel for your Florida home or another project in mind, look no further than Gulf Cast Design Build as YourTop Rated Laundry Room Remodeling Company in Florida To know more details: https://gulfcoastdesignbuild.com/laundry-room-remodeling/

    ReplyDelete

Search This Blog