Skip to Content
Mastering JavaScript Functional Programming - Second Edition
book

Mastering JavaScript Functional Programming - Second Edition

by Federico Kereki
January 2020
Intermediate to advanced
470 pages
11h 13m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming - Second Edition

Getting a property from an object

There is a simple function that we could also produce. Extracting an attribute from an object is a commonly required operation. For example, in Chapter 5, Programming Declaratively  A Better Style, we had to get latitudes and longitudes to be able to calculate an average. The code for this was as follows:

markers = [  {name: "UY", lat: -34.9, lon: -56.2},  {name: "AR", lat: -34.6, lon: -58.4},  {name: "BR", lat: -15.8, lon: -47.9},  ...  {name: "BO", lat: -16.5, lon: -68.1}];let averageLat = average(markers.map(x => x.lat));let averageLon = average(markers.map(x => x.lon));

We saw another example of this when we learned how to filter an array; in our example, we wanted to get the IDs for all the accounts with ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Functional Programming

Mastering JavaScript Functional Programming

Federico Kereki

Publisher Resources

ISBN: 9781839213069Supplemental Content