Quick example on how you can use jQuery’s $.map() function to grab a value from an array of JS objects. In the example I have an array of JS objects that contain days and prices, we want to extract a price for a specific day.

var dayArr = Array( { "day" : "day01", "price" : "$210" }, { "day" : "day02", "price" : "$220" }, { "day" : "day03", "price" : "$230" } );

var findDay = 'day02'; //find price for day 1

var price = $.map(dayArr, function(value, key) {
     if (value.day == findDay)
        return value.price;
//output: $220
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

No Reader comments

Learn JavaScript for free!
Free course: Introduction to JavaScript

Yours when you take up a free 14-day SitePoint Premium trial.