Categories: Uncategorized

jQuery – $.each vs $.map jquery

We are going to go over what are the difference between $.each and $.map in jquery. Both are like foreach loops, but utilized differently.

The each method is meant to be an immutable iterator, where as the map method can be used as an iterator, but is really meant to manipulate the supplied array and return a new array.

Another important thing to note is that the each function returns the original array while the mapfunction returns a new array. If you overuse the return value of the map function you can potentially waste a lot of memory.

<script>
    var cities = ['Paris', 'London', 'Orlando'];
    
    $.each(cities, function(index, city){
        var result = city + " " + index;
        console.log(result);
    });
    // paris 0
    // london 1
    // orlando 2

    $.map(cities, function(city, index){
        var result = city + " " + index;
        console.log(result);
        return result;
    });
    // paris 0
    // london 1
    // orlando 2

</script>
Admin

Recent Posts

Unveiling the Intricacies of the Tinder Algorithm: 5 Surprising Metrics

Monitored by Tinder The inner workings of the Tinder algorithm remain shrouded in secrecy, known…

3 weeks ago

Is Shopping Temu Safe

Use fav19073 30% OFF Shop Now I recently had a fantastic buying experience on Temu,…

4 months ago

Cheap Netflix Subscription

Unlocking Affordable Streaming: How Gamsgo.com is Revolutionizing Netflix Subscriptions Sign Up Save1 coupon code for…

4 months ago

Domains for SALE.

razerkeyb.com gloriousmouse.com

9 months ago

How to Start your own vegetable garden?

Planting your own vegetables and fruit is a great way to save money and eat…

1 year ago

Jobs AI can’t replace

While AI has the potential to automate many tasks, there are still some jobs that…

1 year ago